/**
 @date 2009-12-22

 @version v2.0

---file comments----
*/

/****************************************************************************
 *
 * Header files
 *
 *****************************************************************************/
#include "sal.h"
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctc_api.h"
#include "ctcs_api.h"
#include "ctc_error.h"
#include "ctc_debug.h"
#include "ctc_acl_cli.h"
#include "ctc_qos_cli.h"
#include "ctc_mirror.h"
#include "ctc_security.h"

#define CTC_QUEUE_NUM_PER_PORT 12
#define CTC_QUEUE_NUM_PER_REASON 32
#define CTC_SCH_GRP_MAX_CHILD_CNT 1216
#define CTC_QOS_FLEXQ_MAP_PROFILE 30

#define CTC_POLICER_TYPE_ALL_STR "((chan|)port GPORT (in|out)|flow POLICER_ID|service SERVICE_ID|vlan VLAN_ID(in|out)| \
        copp POLICER_ID|mfp POLICER_ID)"
        
#define CTC_POLICER_TYPE_ALL_DESC \
        "Channel policer",\
        CTC_CLI_GPORT_DESC,\
        CTC_CLI_GPHYPORT_ID_DESC,\
        "Ingress direction",\
        "Egress direction",\
        CTC_CLI_QOS_FLOW_PLC_STR,\
        CTC_CLI_QOS_FLOW_PLC_VAL,\
        "Service policer",\
        CTC_CLI_QOS_SERVICE_VAL,\
        CTC_CLI_QOS_VLAN_PLC_STR,\
        CTC_CLI_QOS_FLOW_PLC_VAL,\
        "Ingress direction",\
        "Egress direction",\
        CTC_CLI_QOS_COPP,\
        CTC_CLI_QOS_FLOW_PLC_VAL,\
        "Micro flow policer for ipfix",\
        CTC_CLI_QOS_FLOW_PLC_VAL

#define CTC_QOS_BUFFER_TYPE_STR "(port-prio-class GPORT PRIO_CLASS|queue "CTC_CLI_QOS_QUEUE_ID_STR"|port-sc GPORT SC| \
        port GPORT|sc SC_ID|critical|c2c|total)"
        
#define CTC_QOS_BUFFER_TYPE_DESC \
        "Port Tc buffer type",\
        CTC_CLI_GPHYPORT_ID_DESC,\
        "Tc value",\
        "QoS Queue",\
        CTC_CLI_QOS_QUEUE_ID_DSCP,\
        "Port Sc buffer type",\
        CTC_CLI_GPHYPORT_ID_DESC,\
        "Sc value",\
        CTC_CLI_GPORT_DESC,\
        CTC_CLI_GPHYPORT_ID_DESC,\
        "Sc buffer type",\
        "Sc value",\
        "Control buffer type",\
        "C2C buffer type",\
        "Total buffer type"

int32  _ctc_cli_qos_buffer_type_parser(ctc_vti_t* vty, uint8 *buffer_type, char** argv, uint16 argc)
{
    uint8 index = 0xFF;

    *buffer_type = CTC_QOS_BUFFER_MAX;
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        /* port type */
        *buffer_type = CTC_QOS_BUFFER_PORT;
    }
    /* queue type */
    index = CTC_CLI_GET_ARGC_INDEX("queue");
    if (0xFF != index)
    {
        *buffer_type = CTC_QOS_BUFFER_QUEUE;
    }
    /* total type */
    index = CTC_CLI_GET_ARGC_INDEX("total");
    if (0xFF != index)
    {
        *buffer_type = CTC_QOS_BUFFER_TOTAL;
    }
    /* c2c type */
    index = CTC_CLI_GET_ARGC_INDEX("c2c");
    if (0xFF != index)
    {
        *buffer_type = CTC_QOS_BUFFER_C2C;
    }
    /* control type */
    index = CTC_CLI_GET_ARGC_INDEX("control");
    if (0xFF != index)
    {
        *buffer_type = CTC_QOS_BUFFER_CONTROL;
    }
    /* sc type */
    index = CTC_CLI_GET_ARGC_INDEX("sc");
    if (0xFF != index)
    {
        *buffer_type = CTC_QOS_BUFFER_SC;
    }
    /* port-sc type */
    index = CTC_CLI_GET_ARGC_INDEX("port-sc");
    if (0xFF != index)
    {
        *buffer_type = CTC_QOS_BUFFER_PORT_SC;
    }
    /* port-prio type */
    index = CTC_CLI_GET_ARGC_INDEX("port-prio-class");
    if (0xFF != index)
    {
        *buffer_type = CTC_QOS_BUFFER_PORT_PRIO_CLASS;
    }

    return (*buffer_type == CTC_QOS_BUFFER_MAX) ? CLI_ERROR : CLI_SUCCESS;
}

uint16 g_ctc_cli_drop[CTC_QUEUE_NUM_PER_PORT][3];
#define g_qos_drop_array        ((ctc_qos_drop_t*)CTC_VTY_CLIENT(vty)->qos_drop_array)
#define CTC_CLI_QOS_DROP_ARRAY_INIT     \
{\
    if (!CTC_VTY_CLIENT(vty)->qos_drop_array) {\
        CTC_VTY_CLIENT(vty)->qos_drop_array = mem_malloc(MEM_CLI_MODULE, sizeof(ctc_qos_drop_array)); \
        if (!CTC_VTY_CLIENT(vty)->qos_drop_array) { return CLI_ERROR; }\
        sal_memset(CTC_VTY_CLIENT(vty)->qos_drop_array, 0, sizeof(ctc_qos_drop_array));\
    }\
}

int32 ctc_cli_queue_drop_thrd_init(void)
{
    uint8 i = 0;
    uint8 j = 0;
    uint16 drop_base = 256;

    for (i = 0; i < CTC_QUEUE_NUM_PER_PORT; i++)
    {
        for (j = 0; j < 3; j++)
        {
            g_ctc_cli_drop[i][j] = drop_base + j*128 + i*512;
        }
    }

    return CLI_SUCCESS;
}

int32  _ctc_cli_qos_queue_id_parser(ctc_vti_t* vty, ctc_qos_queue_id_t *p_queue, char** argv, uint16 argc)
{
    uint32 gport = 0;
    uint16  qid = 0;
    uint8 index = 0;
    uint16 service_id = 0;
    uint16 reason_id = 0;
    uint8 class_prio = 0;
    uint8 queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;
    int32 ret = CLI_SUCCESS;

    index = CTC_CLI_GET_ARGC_INDEX("service-id");
    if (0xFF != index)
    {
        /* service id */
        CTC_CLI_GET_UINT16("service-id", service_id, argv[index + 1]);
        queue_type = CTC_QUEUE_TYPE_SERVICE_INGRESS;
    }

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        /* port */
        CTC_CLI_GET_UINT32("gport", gport, argv[index + 1]);
        if (CTC_GPORT_TYPE(gport) == CTC_GPORT_TYPE_DMA)
        {
            queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        /* queue-id */
        CTC_CLI_GET_UINT16("queue-id", qid, argv[index+1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("class-prio");
    if (0xFF != index)
    {
        /* class-prio */
        CTC_CLI_GET_UINT16("class-prio", class_prio, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("reason-id");
    if (0xFF != index)
    {
        /* cpu reason id */
        CTC_CLI_GET_UINT16("reason-id", reason_id, argv[index + 1]);
        queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
    }

    index = CTC_CLI_GET_ARGC_INDEX("rep");
    if (0xFF != index)
    {
        /* replication queue id */
        queue_type = CTC_QUEUE_TYPE_REP;
    }

    p_queue->queue_type = queue_type;
    p_queue->gport      = gport;
    p_queue->service_id = service_id;
    p_queue->queue_id   = qid;
    p_queue->class_prio = class_prio;
    p_queue->cpu_reason = reason_id;

    return ret;

}

void _ctc_cli_queue_drop_wred_show(ctc_vti_t* vty, ctc_qos_drop_t drop_param, uint8 non_ecn)
{
    ctc_cli_out("%-30s: %s\n", "Drop Mode", "WRED");
    ctc_cli_out("%-30s: %u\n", "WRED Weight ", drop_param.drop.weight);
    ctc_cli_out("%-30s: %u\n", "WRED Ecn ", !non_ecn);

    ctc_cli_out("%-30s: %-8u%-8u%-8u%-8u\n",
                "MaxThrd", drop_param.drop.max_th[0],
                 drop_param.drop.max_th[1],
                 drop_param.drop.max_th[2],
                 drop_param.drop.max_th[3]);
    ctc_cli_out("%-30s: %-8u%-8u%-8u%-8u\n",
                "MinThrd", drop_param.drop.min_th[0],
                 drop_param.drop.min_th[1],
                 drop_param.drop.min_th[2],
                 drop_param.drop.min_th[3]);
    ctc_cli_out("%-30s: %-8u%-8u%-8u%-8u\n",
                "DropProb", drop_param.drop.drop_prob[0],
                 drop_param.drop.drop_prob[1],
                 drop_param.drop.drop_prob[2],
                 drop_param.drop.drop_prob[3]);
}
void _ctc_cli_queue_drop_wtd_show(ctc_vti_t* vty, ctc_qos_drop_t drop_param)
{
    ctc_cli_out("%-30s: %s\n", "Drop Mode", "WTD");
    ctc_cli_out("%-30s: %u\n", "WTD and WRED coexist ", drop_param.drop.is_coexist);
    if(drop_param.drop.is_dynamic == 0)
    {
        ctc_cli_out("%-30s: %-8u%-8u%-8u%-8u\n",
                    "DropThrd", drop_param.drop.max_th[0],
                     drop_param.drop.max_th[1],
                     drop_param.drop.max_th[2],
                     drop_param.drop.max_th[3]);
        ctc_cli_out("%-30s: %-8u%-8u%-8u%-8u\n",
                    "EcnThrdColor", drop_param.drop.ecn_th[0],
                     drop_param.drop.ecn_th[1],
                     drop_param.drop.ecn_th[2],
                     drop_param.drop.ecn_th[3]);
        ctc_cli_out("%-30s: %-8u\n",
                    "EcnThrd", drop_param.drop.ecn_mark_th);
    }
    else
    {
        ctc_cli_out("%-30s: %-8u%-8u%-8u%-8u\n",
                    "DropFactor", drop_param.drop.drop_factor[0],
                     drop_param.drop.drop_factor[1],
                     drop_param.drop.drop_factor[2],
                     drop_param.drop.drop_factor[3]);
        ctc_cli_out("%-30s: %-8u%-8u%-8u%-8u\n",
                    "EcnThrdColor", drop_param.drop.ecn_th[0],
                     drop_param.drop.ecn_th[1],
                     drop_param.drop.ecn_th[2],
                     drop_param.drop.ecn_th[3]);
        ctc_cli_out("%-30s: %-8u\n",
                    "EcnThrd", drop_param.drop.ecn_mark_th);
    }
}
int32 ctc_cli_update_queue_drop_thrd(ctc_vti_t* vty, ctc_qos_queue_id_t *p_queue, uint32 weight)
{
    int32 ret  = CLI_SUCCESS;
    uint8 i = 0;
    ctc_qos_drop_t drop_param;
    ctc_qos_queue_drop_t drop;

    if (weight >= 256)
    {
        ctc_cli_out("WARNING weight exceed max  255!!, schedule not correct!!\n");
        return CLI_SUCCESS;
    }

    sal_memset(&drop_param, 0, sizeof(ctc_qos_drop_t));
    sal_memset(&drop, 0, sizeof(ctc_qos_queue_drop_t));

    i = weight/32;

    drop.mode = CTC_QUEUE_DROP_WTD;
    drop.max_th[0] = g_ctc_cli_drop[i][0];
    drop.max_th[1] = g_ctc_cli_drop[i][1];
    drop.max_th[2] = g_ctc_cli_drop[i][2];
    drop.max_th[3] = 0x44;

    sal_memcpy(&drop_param.queue, p_queue, sizeof(ctc_qos_queue_id_t));
    sal_memcpy(&drop_param.drop, &drop, sizeof(ctc_qos_queue_drop_t));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_drop_scheme(g_api_ldev, &drop_param);
    }
    else
    {
        ret = ctc_qos_set_drop_scheme(&drop_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


#define policer_cli ""

CTC_CLI(ctc_cli_qos_set_policer_first,
        ctc_cli_qos_set_policer_first_cmd,
        "qos policer (in | out | both) (flow-first | port-first)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Ingress direction",
        "Egress direction",
        "Both direction",
        "Flow policer first",
        "Port policer first")
{
    uint8 dir = CTC_INGRESS;
    int32 ret  = CLI_SUCCESS;
    uint8 flow_first_en = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    /* parse direction */
    if (CLI_CLI_STR_EQUAL("i", 0))
    {
        dir = CTC_INGRESS;
    }
    else if (CLI_CLI_STR_EQUAL("o", 0))
    {
        dir = CTC_EGRESS;
    }
    else
    {
        dir = CTC_BOTH_DIRECTION;
    }

    /* parse policer first */
    if (CLI_CLI_STR_EQUAL("flow", 1))
    {
        flow_first_en = 1;
    }
    else
    {
        flow_first_en = 0;
    }

    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_FLOW_FIRST_EN;
    glb_cfg.u.value = ((dir << 16) | flow_first_en);
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_set_resrc_mgr_enable,
        ctc_cli_qos_set_resrc_mgr_enable_cmd,
        "qos resrc-mgr (enable | disable)",
        CTC_CLI_QOS_STR,
        "Resource manage",
        "Globally enable",
        "Globally disable")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    if (CLI_CLI_STR_EQUAL("e", 0))
    {
        glb_cfg.u.value = 1;
    }
    else
    {
        glb_cfg.u.value = 0;
    }

    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_RESRC_MGR_EN;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_set_policer_configure,
        ctc_cli_qos_set_policer_configure_cmd,
        "qos policer (sequential | ipg | update |hbwp-share| ecn-mark| port-stbm) (enable | disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Sequential policer",
        "Ipg used for policer",
        "Update token",
        "HBWP share mode",
        "ECN mark",
        "Port policer mode stbm",
        "Globally enable ",
        "Globally disable")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    if (CLI_CLI_STR_EQUAL("ipg", 0))
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_IPG_EN;
    }
    else if (CLI_CLI_STR_EQUAL("update", 0))
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_EN;
    }
    else if (CLI_CLI_STR_EQUAL("hbwp-share", 0))
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_HBWP_SHARE_EN;
    }
    else if (CLI_CLI_STR_EQUAL("ecn-mark", 0))
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_MARK_ECN_EN;
    }
    else if (CLI_CLI_STR_EQUAL("port-stbm", 0))
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_PORT_STBM_EN;
    }
    else
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_SEQENCE_EN;
    }

    if (CLI_CLI_STR_EQUAL("e", 1))
    {
        glb_cfg.u.value = 1;
    }
    else
    {
        glb_cfg.u.value = 0;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_qos_set_phb_configure,
        ctc_cli_qos_set_phb_configure_cmd,
        "qos map priority PRIORITY to phb PHB",
        CTC_CLI_QOS_STR,
        "Map",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "To",
        "PHB,regard as cos index",
        "Value")
{
    int32 ret = CLI_SUCCESS;
    uint8 priority = 0;
    uint8 phb = 0;
    ctc_qos_glb_cfg_t glb_cfg;
    ctc_qos_phb_map_t phb_map;
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    sal_memset(&phb_map, 0, sizeof(ctc_qos_phb_map_t));
    CTC_CLI_GET_UINT8("priority", priority, argv[0]);
    CTC_CLI_GET_UINT8("phb", phb, argv[1]);

    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_PHB_MAP;
    phb_map.map_type = CTC_QOS_PHB_MAP_PRI;
    phb_map.priority = priority;
    phb_map.cos_index = phb;
    sal_memcpy(&glb_cfg.u.phb_map, &phb_map, sizeof(ctc_qos_phb_map_t));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}

CTC_CLI(ctc_cli_qos_get_phb_configure,
        ctc_cli_qos_get_phb_configure_cmd,
        "show qos map priority PRIORITY",
        "Show",
        CTC_CLI_QOS_STR,
        "Map",
        "Priority",
        CTC_CLI_PRIORITY_VALUE)
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t glb_cfg;
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    CTC_CLI_GET_UINT8("priority", glb_cfg.u.phb_map.priority, argv[0]);

    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_PHB_MAP;
    glb_cfg.u.phb_map.map_type = CTC_QOS_PHB_MAP_PRI;
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_get_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("\nPriority to Phb Information:\n");
    ctc_cli_out("%-10s %-10s\n","Priority", "Phb");
    ctc_cli_out("-----------------------------------------\n");
    ctc_cli_out("%-10d %-10d\n",glb_cfg.u.phb_map.priority,glb_cfg.u.phb_map.cos_index);
    return ret;
}
CTC_CLI(ctc_cli_qos_create_policer,
        ctc_cli_qos_create_policer_cmd,
        "qos policer attach "CTC_POLICER_TYPE_ALL_STR" (mode (rfc2697|rfc2698|rfc4115|bwp|stbm)) ((color-blind|color-aware)|) \
         (cir CIR) (cbs CBS |) ((pir PIR|eir EIR)|) ((pbs PBS|ebs EBS)|) (cf-en|)(color-merge-mode VALUE|)(drop-color (none|red|yellow)|) (use-l3-length|) (stats-en|) (stats-mode MODE|) \
         ((hbwp-en schedule-mode (sp|wdrr weight WEIGHT) cos-index INDEX max-cir CIR_MAX (max-eir EIR_MAX|)(sf-en|) (cf-total-dis|) (triple-play|))|) \
         (action {priority-green VALUE | priority-yellow VALUE | priority-red VALUE | drop-green | drop-yellow | drop-red}| ) (level LEVEL|) (pps-en|) (granu VALUE|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Attach policer",
        CTC_POLICER_TYPE_ALL_DESC,
        "Policer mode",
        "RFC2697, srTCM",
        "RFC2698, trTCM",
        "RFC4115, enhaned trTCM",
        "MEF 10.1,bandwidth profile",
        "STBM, Single Token Bucket Meter",
        "Color blind mode, default policing mode",
        "Color aware mode",
        CTC_CLI_QOS_PLC_CIR_STR,
        CTC_CLI_QOS_PLC_CIR_VAL,
        CTC_CLI_QOS_PLC_CBS_STR,
        CTC_CLI_QOS_PLC_CBS_VAL,
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_EIR_STR,
        CTC_CLI_QOS_PLC_EIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_PLC_PBS_VAL,
        CTC_CLI_QOS_PLC_EBS_STR,
        CTC_CLI_QOS_PLC_EBS_VAL,
        "Couple flag enable, only for BWP",
        "Color merge mode,only for 2 level policer",
        "Value",
        "Drop color config",
        "None",
        "Red, default drop color",
        "Yellow",
        "Use packet length from layer 3 header for metering",
        "Stats enable",
        "Stats mode",
        "Mode Value",
        "HBWP enable, only support service policer on GB",
        "scheulde mode",
        "Strict priority",
        "Wdrr, GB only support cos 0 and cos 1, other is SP",
        "Weight",
        "Weight value, GB only support cos 1 weight, cos 0 is (0x3FF - Weight)",
        "Cos index",
        "Value",
        "Cir max",
        CTC_CLI_QOS_PLC_EIR_STR,
        "Pir max",
        CTC_CLI_QOS_PLC_EIR_STR,
        "Share flag enable",
        "Coupling total disable",
        "Triple play mode, if set, cos_max=3",
        "Policer action",
        "Green priority",
        CTC_CLI_PRIORITY_VALUE,
        "Yellow priority",
        CTC_CLI_PRIORITY_VALUE,
        "Red priority",
        CTC_CLI_PRIORITY_VALUE,
        "Drop green",
        "Drop yellow",
        "Drop red",
        "Policer level",
        "Policer level value",
        "PPS enable",
        "Granularity",
        "Granularity value, unit:kbps")
{
    ctc_qos_policer_t policer_param;
    uint32 gport = 0;
    int16 idx = 0;
    int16 idx1 = 0;
    uint8 dir = 0;
    int32 ret = CLI_SUCCESS;

    sal_memset(&policer_param, 0, sizeof(ctc_qos_policer_t));

    /* policer id */
    policer_param.dir = CTC_INGRESS;
    policer_param.enable = 1;
    /* init default params */
    policer_param.policer.is_color_aware = 0;
    policer_param.policer.cbs = 64;
    policer_param.policer.pbs = 64;
    policer_param.policer.drop_color = CTC_QOS_COLOR_RED;
    policer_param.policer.use_l3_length = 0;

    /*------------------------------------------
     ##policer type
    --------------------------------------------*/

    /* port policer */
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        policer_param.id.gport = gport;
        policer_param.type = CTC_QOS_POLICER_TYPE_PORT;

        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        policer_param.dir = dir;

        idx = CTC_CLI_GET_ARGC_INDEX("chan");
        if (0xFF != idx)
        {
            policer_param.type = CTC_QOS_POLICER_TYPE_CHAN;
        }
    }

    /* flow policer */
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }

    /* service policer */
    idx = CTC_CLI_GET_ARGC_INDEX("service");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("service id", policer_param.id.service_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_SERVICE;
    }

    /* vlan policer */
    idx = CTC_CLI_GET_ARGC_INDEX("vlan");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.vlan_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_VLAN;
        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        policer_param.dir = dir;
    }
    /* copp */
    idx = CTC_CLI_GET_ARGC_INDEX("copp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_COPP;
    }
    /* mfp */
    idx = CTC_CLI_GET_ARGC_INDEX("mfp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_MFP;
    }

    /*------------------------------------------
     ##policer mode
    --------------------------------------------*/

    idx = CTC_CLI_GET_ARGC_INDEX("mode");
    if (0xFF != idx)
    {
        if (CLI_CLI_STR_EQUAL("rfc2697", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_RFC2697;
        }
        else if(CLI_CLI_STR_EQUAL("rfc2698", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_RFC2698;
        }
        else if(CLI_CLI_STR_EQUAL("rfc4115", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_RFC4115;
        }
        else if(CLI_CLI_STR_EQUAL("bwp", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_MEF_BWP;
        }
        else if(CLI_CLI_STR_EQUAL("stbm", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_STBM;
        }
    }


    /*------------------------------------------
     ##policer common paramete
    --------------------------------------------*/

    /* color blind */
    idx = CTC_CLI_GET_ARGC_INDEX("color-blind");
    if (0xFF != idx)
    {
        policer_param.policer.is_color_aware = 0;
    }

    /* color aware */
    idx = CTC_CLI_GET_ARGC_INDEX("color-aware");
    if (0xFF != idx)
    {
        policer_param.policer.is_color_aware = 1;
    }

    /* cir */
    idx = CTC_CLI_GET_ARGC_INDEX("cir");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("cir", policer_param.policer.cir, argv[idx + 1]);
    }

    /* cbs */
    idx = CTC_CLI_GET_ARGC_INDEX("cbs");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("cbs", policer_param.policer.cbs, argv[idx + 1]);
    }

    /* pir */
    idx = CTC_CLI_GET_ARGC_INDEX("pir");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("pir", policer_param.policer.pir, argv[idx + 1]);
    }

    /* eir */
    idx = CTC_CLI_GET_ARGC_INDEX("eir");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("eir", policer_param.policer.pir, argv[idx + 1]);
    }

    /* pbs */
    idx = CTC_CLI_GET_ARGC_INDEX("pbs");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("pbs", policer_param.policer.pbs, argv[idx + 1]);
    }

    /* ebs */
    idx = CTC_CLI_GET_ARGC_INDEX("ebs");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("ebs", policer_param.policer.pbs, argv[idx + 1]);
    }

    /* couple flag */
    idx = CTC_CLI_GET_ARGC_INDEX("cf-en");
    if (0xFF != idx)
    {
        policer_param.policer.cf_en = 1;
    }
    /* couple flag */
    idx = CTC_CLI_GET_ARGC_INDEX("color-merge-mode");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT8("color-merge-mode", policer_param.policer.color_merge_mode, argv[idx + 1]);
    }

    /* drop color */
    idx = CTC_CLI_GET_ARGC_INDEX("drop-color");
    if (0xFF != idx)
    {
        if (CLI_CLI_STR_EQUAL("red", idx + 1))
        {
            policer_param.policer.drop_color = CTC_QOS_COLOR_RED;
        }
        else if (CLI_CLI_STR_EQUAL("yel", idx + 1))
        {
            policer_param.policer.drop_color = CTC_QOS_COLOR_YELLOW;
        }
        else if (CLI_CLI_STR_EQUAL("none", idx + 1))
        {
            policer_param.policer.drop_color = CTC_QOS_COLOR_NONE;
        }
    }

    /* use l3 length */
    idx = CTC_CLI_GET_ARGC_INDEX("use-l3-length");
    if (0xFF != idx)
    {
        policer_param.policer.use_l3_length = 1;
    }

    /* enable stats */
    idx = CTC_CLI_GET_ARGC_INDEX("stats-en");
    if (0xFF != idx)
    {
        policer_param.policer.stats_en = TRUE;
    }

    if (policer_param.policer.policer_mode == CTC_QOS_POLICER_MODE_RFC2697)
    {
        policer_param.policer.pir = policer_param.policer.cir;
    }

    idx = CTC_CLI_GET_ARGC_INDEX("stats-mode");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("mode", policer_param.policer.stats_mode, argv[idx + 1]);
    }

    /* hbwp policer */
    idx1 = CTC_CLI_GET_ARGC_INDEX("hbwp-en");
    if (0xFF != idx1)
    {
        policer_param.hbwp_en = 1;

        idx = CTC_CLI_GET_SPECIFIC_INDEX("wdrr", idx1);
        if (0xFF != idx)
        {
            policer_param.hbwp.sp_en = 0;
            CTC_CLI_GET_UINT16("weigth", policer_param.hbwp.weight, argv[idx1 + idx + 2]);
        }
        else
        {
            policer_param.hbwp.sp_en = 1;
        }

        idx = CTC_CLI_GET_SPECIFIC_INDEX("cos-index", idx1);
        if (0xFF != idx)
        {
            CTC_CLI_GET_UINT8("cos-index", policer_param.hbwp.cos_index, argv[idx1 + idx + 1]);
        }


        idx = CTC_CLI_GET_SPECIFIC_INDEX("max-cir", idx1);
        if (0xFF != idx)
        {
            CTC_CLI_GET_UINT32("cir-max", policer_param.hbwp.cir_max, argv[idx1 + idx + 1]);
        }

        idx = CTC_CLI_GET_SPECIFIC_INDEX("max-eir", idx1);
        if (0xFF != idx)
        {
            CTC_CLI_GET_UINT32("pir-max", policer_param.hbwp.pir_max, argv[idx1 + idx + 1]);
        }

        idx = CTC_CLI_GET_SPECIFIC_INDEX("sf-en", idx1);
        if (0xFF != idx)
        {
            policer_param.hbwp.sf_en = 1;
        }

        idx = CTC_CLI_GET_SPECIFIC_INDEX("cf-total-dis", idx1);
        if (0xFF != idx)
        {
            policer_param.hbwp.cf_total_dis = 1;
        }

        idx = CTC_CLI_GET_SPECIFIC_INDEX("triple-play", idx1);
        if (0xFF != idx)
        {
            policer_param.hbwp.triple_play = 1;
        }

    }

    /* action */
    idx = CTC_CLI_GET_ARGC_INDEX("action");
    if (0xFF != idx)
    {
        /* priority-green */
        idx = CTC_CLI_GET_ARGC_INDEX("priority-green");
        if (0xFF != idx)
        {
            CTC_CLI_GET_UINT32("priority-green", policer_param.action.prio_green, argv[idx + 1]);
            SET_FLAG(policer_param.action.flag, CTC_QOS_POLICER_ACTION_FLAG_PRIORITY_GREEN_VALID);
        }

        /* priority-yellow */
        idx = CTC_CLI_GET_ARGC_INDEX("priority-yellow");
        if (0xFF != idx)
        {
            CTC_CLI_GET_UINT32("priority-yellow", policer_param.action.prio_yellow, argv[idx + 1]);
            SET_FLAG(policer_param.action.flag, CTC_QOS_POLICER_ACTION_FLAG_PRIORITY_YELLOW_VALID);
        }

        /* priority-red */
        idx = CTC_CLI_GET_ARGC_INDEX("priority-red");
        if (0xFF != idx)
        {
            CTC_CLI_GET_UINT32("priority-red", policer_param.action.prio_red, argv[idx + 1]);
            SET_FLAG(policer_param.action.flag, CTC_QOS_POLICER_ACTION_FLAG_PRIORITY_RED_VALID);
        }
        /* drop-green */
        idx = CTC_CLI_GET_ARGC_INDEX("drop-green");
        if (0xFF != idx)
        {
            SET_FLAG(policer_param.action.flag, CTC_QOS_POLICER_ACTION_FLAG_DROP_GREEN);
        }

        /* drop-yellow */
        idx = CTC_CLI_GET_ARGC_INDEX("drop-yellow");
        if (0xFF != idx)
        {
            SET_FLAG(policer_param.action.flag, CTC_QOS_POLICER_ACTION_FLAG_DROP_YELLOW);
        }

        /* drop-red */
        idx = CTC_CLI_GET_ARGC_INDEX("drop-red");
        if (0xFF != idx)
        {
            SET_FLAG(policer_param.action.flag, CTC_QOS_POLICER_ACTION_FLAG_DROP_RED);
        }

    }

    /* policer level */
    idx = CTC_CLI_GET_ARGC_INDEX("level");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("level", policer_param.level, argv[idx + 1]);
    }

    /* pps mode */
    idx = CTC_CLI_GET_ARGC_INDEX("pps-en");
    if (0xFF != idx)
    {
        policer_param.pps_en = TRUE;
    }

    /* Granularity */
    idx = CTC_CLI_GET_ARGC_INDEX("granu");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("gran", policer_param.gran, argv[idx + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_policer(g_api_ldev, &policer_param);
    }
    else
    {
        ret = ctc_qos_set_policer(&policer_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_remove_policer,
        ctc_cli_qos_remove_policer_cmd,
        "qos policer detach "CTC_POLICER_TYPE_ALL_STR" \
        (hbwp-en cos-index INDEX |)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Detach policer",
        CTC_POLICER_TYPE_ALL_DESC,
        "Hbwp policer",
        "Specify the cos index",
        "Value")
{
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    int16 idx1 = 0;
    uint8 dir = 0;
    uint32 gport = 0;
    ctc_qos_policer_t policer_param;

    sal_memset(&policer_param, 0, sizeof(ctc_qos_policer_t));

    /* policer id */
    policer_param.dir = CTC_INGRESS;
    policer_param.enable = 0;

    /*------------------------------------------
     ##policer type
    --------------------------------------------*/

    /* port policer */
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        policer_param.id.gport = gport;
        policer_param.type = CTC_QOS_POLICER_TYPE_PORT;

        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        policer_param.dir = dir;

        idx = CTC_CLI_GET_ARGC_INDEX("chan");
        if (0xFF != idx)
        {
            policer_param.type = CTC_QOS_POLICER_TYPE_CHAN;
        }

    }

    /* flow policer */
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }

    /* service policer */
    idx = CTC_CLI_GET_ARGC_INDEX("service");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("service id", policer_param.id.service_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_SERVICE;
    }

    /* vlan policer */
    idx = CTC_CLI_GET_ARGC_INDEX("vlan");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("vlan id", policer_param.id.vlan_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_VLAN;
        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        policer_param.dir = dir;
    }
    /* copp */
    idx = CTC_CLI_GET_ARGC_INDEX("copp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_COPP;
    }
    /* mfp */
    idx = CTC_CLI_GET_ARGC_INDEX("mfp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_MFP;
    }

    /* hbwp policer */
    idx1 = CTC_CLI_GET_ARGC_INDEX("hbwp-en");
    if (0xFF != idx1)
    {
        policer_param.hbwp_en = 1;
        CTC_CLI_GET_UINT16("cos-index", policer_param.hbwp.cos_index, argv[idx1 + 2]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_policer(g_api_ldev, &policer_param);
    }
    else
    {
        ret = ctc_qos_set_policer(&policer_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_show_policer_stats,
        ctc_cli_qos_show_policer_stats_cmd,
        "show qos policer stats "CTC_POLICER_TYPE_ALL_STR" (hbwp-en cos-index INDEX |)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Statistics",
        CTC_POLICER_TYPE_ALL_DESC,
        "Hbwp policer",
        "Specify the cos index",
        "Value")
{

    ctc_qos_policer_stats_t stats_param;
    char   stats_pkts[UINT64_STR_LEN], stats_bytes[UINT64_STR_LEN];
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    int16 idx1 = 0;
    uint8 dir = 0;
    uint32 gport = 0;

    sal_memset(&stats_param, 0, sizeof(ctc_qos_policer_stats_t));

    /* port policer */
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        stats_param.id.gport = gport;
        stats_param.type = CTC_QOS_POLICER_TYPE_PORT;

        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        stats_param.dir = dir;

        idx = CTC_CLI_GET_ARGC_INDEX("chan");
        if (0xFF != idx)
        {
            stats_param.type = CTC_QOS_POLICER_TYPE_CHAN;
        }

    }

    /* flow policer */
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("policer id", stats_param.id.policer_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }

    /* service policer */
    idx = CTC_CLI_GET_ARGC_INDEX("service");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("service id", stats_param.id.service_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_SERVICE;
    }

    /* copp policer */
    idx = CTC_CLI_GET_ARGC_INDEX("copp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("copp id", stats_param.id.policer_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_COPP;
    }

    /* vlan policer */
    idx = CTC_CLI_GET_ARGC_INDEX("vlan");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("vlan id", stats_param.id.vlan_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_VLAN;
        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        stats_param.dir = dir;
    }
    /* hbwp policer */
    idx1 = CTC_CLI_GET_ARGC_INDEX("hbwp-en");
    if (0xFF != idx1)
    {
        stats_param.hbwp_en = 1;
        CTC_CLI_GET_UINT16("cos-index", stats_param.cos_index, argv[idx1 + 2]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_query_policer_stats(g_api_ldev, &stats_param);
    }
    else
    {
        ret = ctc_qos_query_policer_stats(&stats_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("policer id = %u\n", stats_param.id.policer_id);
    ctc_cli_out("===========================\n");
    ctc_uint64_to_str(stats_param.stats.confirm_pkts, stats_pkts);
    ctc_uint64_to_str(stats_param.stats.confirm_bytes, stats_bytes);
    ctc_cli_out("confirm stats, packet = %s, bytes = %s\n", stats_pkts, stats_bytes);
    ctc_uint64_to_str(stats_param.stats.exceed_pkts, stats_pkts);
    ctc_uint64_to_str(stats_param.stats.exceed_bytes, stats_bytes);
    ctc_cli_out("exceed stats, packet = %s, bytes = %s\n", stats_pkts, stats_bytes);
    ctc_uint64_to_str(stats_param.stats.violate_pkts, stats_pkts);
    ctc_uint64_to_str(stats_param.stats.violate_bytes, stats_bytes);
    ctc_cli_out("violate stats, packet = %s, bytes = %s\n", stats_pkts, stats_bytes);

    return ret;
}

CTC_CLI(ctc_cli_qos_clear_policer_stats,
        ctc_cli_qos_clear_policer_stats_cmd,
        "clear qos policer stats "CTC_POLICER_TYPE_ALL_STR" (hbwp-en cos-index INDEX |)",
        CTC_CLI_CLEAR_STR,
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Statistics",
        CTC_POLICER_TYPE_ALL_DESC,
        "Hbwp policer",
        "Specify the cos index",
        "Value")
{
    ctc_qos_policer_stats_t stats_param;
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    int16 idx1 = 0;
    uint8 dir = 0;
    uint32 gport = 0;
    sal_memset(&stats_param, 0, sizeof(ctc_qos_policer_stats_t));

    /* port policer */
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        stats_param.id.gport = gport;
        stats_param.type = CTC_QOS_POLICER_TYPE_PORT;

        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }

        stats_param.dir = dir;

        idx = CTC_CLI_GET_ARGC_INDEX("chan");
        if (0xFF != idx)
        {
            stats_param.type = CTC_QOS_POLICER_TYPE_CHAN;
        }
    }

    /* flow policer */
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("policer id", stats_param.id.policer_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }

    /* service policer */
    idx = CTC_CLI_GET_ARGC_INDEX("service");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("service id", stats_param.id.service_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_SERVICE;
    }

    /* copp policer */
    idx = CTC_CLI_GET_ARGC_INDEX("copp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("copp id", stats_param.id.policer_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_COPP;
    }

    /* vlan policer */
    idx = CTC_CLI_GET_ARGC_INDEX("vlan");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("vlan id", stats_param.id.vlan_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_VLAN;
        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }

        stats_param.dir = dir;
    }
    /* hbwp policer */
    idx1 = CTC_CLI_GET_ARGC_INDEX("hbwp-en");
    if (0xFF != idx1)
    {
        stats_param.hbwp_en = 1;
        CTC_CLI_GET_UINT16("cos-index", stats_param.cos_index, argv[idx1 + 2]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_clear_policer_stats(g_api_ldev, &stats_param);
    }
    else
    {
        ret = ctc_qos_clear_policer_stats(&stats_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_show_policer,
        ctc_cli_qos_show_policer_cmd,
        "show qos policer "CTC_POLICER_TYPE_ALL_STR" (hbwp-en cos-index INDEX |)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        CTC_POLICER_TYPE_ALL_DESC,
        "Hbwp policer",
        "Specify the cos index",
        "Cos-index Value")
{
    ctc_qos_policer_t policer_param;
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    int16 idx1 = 0;
    uint8 dir = 0;
    uint32 gport = 0;
    uint32 policer_id = 0;
    char policer_mode[5][32] = {"stbm","rfc2697", "rfc2698", "rfc4115", "bwp"};

    sal_memset(&policer_param, 0, sizeof(ctc_qos_policer_t));

    /* port policer */
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        policer_param.id.gport = gport;
        policer_param.type = CTC_QOS_POLICER_TYPE_PORT;
        policer_id = gport;

        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }

        policer_param.dir = dir;

        idx = CTC_CLI_GET_ARGC_INDEX("chan");
        if (0xFF != idx)
        {
            policer_param.type = CTC_QOS_POLICER_TYPE_CHAN;
        }
    }

    /* flow policer */
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_FLOW;
        policer_id = policer_param.id.policer_id;
    }

    /* service policer */
    idx = CTC_CLI_GET_ARGC_INDEX("service");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("service id", policer_param.id.service_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_SERVICE;
        policer_id = policer_param.id.service_id;
    }

    /* vlan policer */
    idx = CTC_CLI_GET_ARGC_INDEX("vlan");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("vlan id", policer_param.id.vlan_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_VLAN;
        /* direction */
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }

        policer_param.dir = dir;
        policer_id = policer_param.id.vlan_id;
    }

    /* copp */
    idx = CTC_CLI_GET_ARGC_INDEX("copp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_COPP;
        policer_id = policer_param.id.policer_id;
    }

    /* copp */
    idx = CTC_CLI_GET_ARGC_INDEX("mfp");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_MFP;
        policer_id = policer_param.id.policer_id;
    }

    /* hbwp policer */
    idx1 = CTC_CLI_GET_ARGC_INDEX("hbwp-en");
    if (0xFF != idx1)
    {
        policer_param.hbwp_en = 1;
        CTC_CLI_GET_UINT8("cos-index", policer_param.hbwp.cos_index, argv[idx1 + 2]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_policer(g_api_ldev, &policer_param);
    }
    else
    {
        ret = ctc_qos_get_policer(&policer_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if (policer_param.type == CTC_QOS_POLICER_TYPE_PORT || CTC_QOS_POLICER_TYPE_CHAN == policer_param.type)
    {
        ctc_cli_out("%-6s %-7s %-7s", "port", "cos_idx", "enable");
    }
    else if (policer_param.type == CTC_QOS_POLICER_TYPE_VLAN)
    {
        ctc_cli_out("%-6s %-7s %-7s", "vlan-id", "cos_idx", "enable");
    }
    else if ((policer_param.type == CTC_QOS_POLICER_TYPE_FLOW) || (policer_param.type == CTC_QOS_POLICER_TYPE_COPP) || (policer_param.type == CTC_QOS_POLICER_TYPE_MFP))
    {
        ctc_cli_out( "%-6s %-7s %-7s", "plc-id", "cos_idx", "enable");
    }
    else
    {
        ctc_cli_out( "%-6s %-7s %-7s", "service-id", "cos_idx", "enable");
    }
    ctc_cli_out( "%-13s %-13s %-12s %-12s %-8s %-7s\n", "cir(kbps/pps)", "pir(kbps/pps)", "cbs(kb/pkt)", "pbs(kb/pkt)",
                             "stats-en", "pps-en");
    ctc_cli_out("--------------------------------------------------------------------------------------------\n");
    ctc_cli_out("0x%04x %-7d %-6d ", policer_id, policer_param.hbwp.cos_index, 1);
    ctc_cli_out("%-13d %-13d %-12d %-12d %-8d %-7d\n", policer_param.policer.cir, policer_param.policer.pir, policer_param.policer.cbs,
                policer_param.policer.pbs, policer_param.policer.stats_en,policer_param.pps_en);
    ctc_cli_out("\nDetail information:\n");
    ctc_cli_out("----------------------------------------------------------\n");
    ctc_cli_out("%-7s %-11s %-11s %-4s %-8s %-8s %-8s %-8s %-7s %-8s\n","stats-mode","policer-mode","color-aware","level","use-l3-length","drop-color","action-pri-green","action-pri-yellow","action-pri-red","color-merge-mod");
    ctc_cli_out("-----------------------------------------------------------------------------------------------------------------------\n");
    ctc_cli_out("%-11d %-11s %-11d %-4d %-17d %-7d %-17d %-17d%-17d%-17d\n",policer_param.policer.stats_mode,policer_mode[policer_param.policer.policer_mode],
                policer_param.policer.is_color_aware,policer_param.level-1,policer_param.policer.use_l3_length, policer_param.policer.drop_color, policer_param.action.prio_green,
                policer_param.action.prio_yellow,policer_param.action.prio_red,policer_param.policer.color_merge_mode);
    if(policer_param.hbwp_en == 1)
    {
        ctc_cli_out("%-7s %-7s %-11s %-7s %-8s %-8s\n","hbwp-en","sf-en","cf-total-dis","cir_max(kbps/pps)","pir_max(kbps/pps)","cf_en");
        ctc_cli_out("------------------------------------------------------------------------------------\n");
        ctc_cli_out("%-7d %-7d %-17d %-17d %-14d %-7d \n",policer_param.hbwp_en,policer_param.hbwp.sf_en,policer_param.hbwp.cf_total_dis,
                    policer_param.hbwp.cir_max,policer_param.hbwp.pir_max, policer_param.policer.cf_en);
    }

    return ret;
}

#define debug_cli ""

CTC_CLI(ctc_cli_qos_debug_on,
        ctc_cli_qos_debug_on_cmd,
        "debug qos (ctc | sys) (policer | class| queue) (debug-level {func|param|info|error} |)",
        CTC_CLI_DEBUG_STR,
        CTC_CLI_QOS_STR,
        "Ctc layer",
        "Sys layer",
        "QoS policer",
        "QoS classification",
        "QoS queue",
        CTC_CLI_DEBUG_LEVEL_STR,
        CTC_CLI_DEBUG_LEVEL_FUNC,
        CTC_CLI_DEBUG_LEVEL_PARAM,
        CTC_CLI_DEBUG_LEVEL_INFO,
        CTC_CLI_DEBUG_LEVEL_ERROR)
{
    uint8 level = CTC_DEBUG_LEVEL_INFO;
    uint8 index = 0;

    index = CTC_CLI_GET_ARGC_INDEX("debug-level");
    if (index != 0xFF)
    {
        level = CTC_DEBUG_LEVEL_NONE;
        index = CTC_CLI_GET_ARGC_INDEX("func");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_FUNC;
        }

        index = CTC_CLI_GET_ARGC_INDEX("param");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_PARAM;
        }

        index = CTC_CLI_GET_ARGC_INDEX("info");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_INFO;
        }

        index = CTC_CLI_GET_ARGC_INDEX("error");
        if (index != 0xFF)
        {
            level |= CTC_DEBUG_LEVEL_ERROR;
        }
    }

    if (CLI_CLI_STR_EQUAL("ctc", 0))
    {
        if (CLI_CLI_STR_EQUAL("pol", 1))
        {
            ctc_debug_set_flag("qos", "policer", QOS_PLC_CTC, level, TRUE);
        }
        else if (CLI_CLI_STR_EQUAL("cla", 1))
        {
            ctc_debug_set_flag("qos", "class", QOS_CLASS_CTC, level, TRUE);
        }
        else
        {
            ctc_debug_set_flag("qos", "queue", QOS_QUE_CTC, level, TRUE);
        }
    }
    else if (CLI_CLI_STR_EQUAL("sys", 0))
    {
        if (CLI_CLI_STR_EQUAL("pol", 1))
        {
            ctc_debug_set_flag("qos", "policer", QOS_PLC_SYS, level, TRUE);
        }
        else if (CLI_CLI_STR_EQUAL("cla", 1))
        {
            ctc_debug_set_flag("qos", "class", QOS_CLASS_SYS, level, TRUE);
        }
        else
        {
            ctc_debug_set_flag("qos", "queue", QOS_QUE_SYS, level, TRUE);
        }
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_debug_off,
        ctc_cli_qos_debug_off_cmd,
        "no debug qos (ctc | sys) (policer | class| queue)",
        CTC_CLI_NO_STR,
        CTC_CLI_DEBUG_STR,
        CTC_CLI_QOS_STR,
        "Ctc layer",
        "Sys layer",
        "QoS policer",
        "QoS classification",
        "QoS queue")
{
    uint8 level = 0;

    if (CLI_CLI_STR_EQUAL("ctc", 0))
    {
        if (CLI_CLI_STR_EQUAL("pol", 1))
        {
            ctc_debug_set_flag("qos", "policer", QOS_PLC_CTC, level, FALSE);
        }
        else if (CLI_CLI_STR_EQUAL("cla", 1))
        {
            ctc_debug_set_flag("qos", "class", QOS_CLASS_CTC, level, FALSE);
        }
        else
        {
            ctc_debug_set_flag("qos", "queue", QOS_QUE_CTC, level, FALSE);
        }
    }
    else if (CLI_CLI_STR_EQUAL("sys", 0))
    {
        if (CLI_CLI_STR_EQUAL("pol", 1))
        {
            ctc_debug_set_flag("qos", "policer", QOS_PLC_SYS, level, FALSE);
        }
        else if (CLI_CLI_STR_EQUAL("cla", 1))
        {
            ctc_debug_set_flag("qos", "class", QOS_CLASS_SYS, level, FALSE);
        }
        else
        {
            ctc_debug_set_flag("qos", "queue", QOS_QUE_SYS, level, FALSE);
        }
    }

    return CLI_SUCCESS;
}

#define domain_map_cli ""

CTC_CLI(ctc_cli_qos_set_igs_domain_map,
        ctc_cli_qos_set_igs_domain_map_cmd,
        "qos (domain DOMAIN) map (cos COS (dei DEI |)| dscp DSCP (ecn ECN |)| ip-prec IP_PREC |exp EXP) \
        to (priority PRIORITY) (color (green |yellow | red)) (new-dscp NEW_DSCP|new-exp NEW_EXP|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_DOMAIN_STR,
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Mapping",
        "Cos",
        "<0-7>",
        "Dei",
        "<0-1>",
        "Dscp",
        "<0-63>",
        "Ecn",
        "ECN value",
        "Ip precedence",
        "<0-7>",
        "Exp",
        "<0-7>",
        "To",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red",
        "New dscp",
        "<0-63>",
        "New exp",
        "<0-7>")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_domain_map_t domain_map;
    uint16 index = 0;


    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));

    index = CTC_CLI_GET_ARGC_INDEX("domain");
    if (0xFF != index)
    {
        /* qos domain */
        CTC_CLI_GET_UINT8("qos domain", domain_map.domain_id, argv[index + 1]);
    }


    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_IGS_COS_TO_PRI_COLOR;

        index = CTC_CLI_GET_ARGC_INDEX("dei");
        if (0xFF != index)
        {
            /* dei */
            CTC_CLI_GET_UINT8("dei", domain_map.hdr_pri.dot1p.dei, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("dscp", domain_map.hdr_pri.tos.dscp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_IGS_DSCP_TO_PRI_COLOR;

        index = CTC_CLI_GET_ARGC_INDEX("ecn");
        if (0xFF != index)
        {
            /* ecn */
            CTC_CLI_GET_UINT8("ecn", domain_map.hdr_pri.tos.ecn, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-prec");
    if (0xFF != index)
    {
        /* ip-prec */
        CTC_CLI_GET_UINT8("ip-prec", domain_map.hdr_pri.ip_prec, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_IGS_IP_PREC_TO_PRI_COLOR;
    }


    index = CTC_CLI_GET_ARGC_INDEX("exp");
    if (0xFF != index)
    {
        /* exp */
        CTC_CLI_GET_UINT8("exp", domain_map.hdr_pri.exp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_IGS_EXP_TO_PRI_COLOR;
    }


    /* priority */
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        /* priority */
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }


    /* color */
    index = CTC_CLI_GET_ARGC_INDEX("green");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_GREEN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("yellow");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_YELLOW;
    }

    index = CTC_CLI_GET_ARGC_INDEX("red");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_RED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("new-dscp");
    if (0xFF != index)
    {
        /* new dscp */
        domain_map.replace_dscp = 1;
        CTC_CLI_GET_UINT8("new-dscp", domain_map.new_dscp, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("new-exp");
    if (0xFF != index)
    {
        /* new exp */
        domain_map.replace_dscp = 1;
        CTC_CLI_GET_UINT8("new-exp", domain_map.new_dscp, argv[index + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_domain_map(g_api_ldev, &domain_map);
    }
    else
    {
        ret = ctc_qos_set_domain_map(&domain_map);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_qos_set_egs_domain_map,
        ctc_cli_qos_set_egs_domain_map_cmd,
        "qos (domain DOMAIN) map (priority PRIORITY) (color (green | yellow | red)) to \
        (cos COS (dei DEI |)| dscp DSCP | exp EXP)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_DOMAIN_STR,
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Mapping",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red",
        "To",
        "Cos",
        "<0-7>",
        "Dei",
        "<0-1>",
        "Dscp",
        "<0-63>",
        "Exp",
        "<0-7>")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_domain_map_t domain_map;
    uint16 index = 0;

    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));

    index = CTC_CLI_GET_ARGC_INDEX("domain");
    if (0xFF != index)
    {
        /* qos domain */
        CTC_CLI_GET_UINT8("qos domain", domain_map.domain_id, argv[index + 1]);
    }

    /* priority */
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }


    /* color */
    index = CTC_CLI_GET_ARGC_INDEX("green");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_GREEN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("yellow");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_YELLOW;
    }

    index = CTC_CLI_GET_ARGC_INDEX("red");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_RED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_COS;

        index = CTC_CLI_GET_ARGC_INDEX("dei");
        if (0xFF != index)
        {
            /* dei */
            CTC_CLI_GET_UINT8("dei", domain_map.hdr_pri.dot1p.dei, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("dscp", domain_map.hdr_pri.tos.dscp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_DSCP;
    }

    index = CTC_CLI_GET_ARGC_INDEX("exp");
    if (0xFF != index)
    {
        /* exp */
        CTC_CLI_GET_UINT8("exp", domain_map.hdr_pri.exp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_EXP;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_domain_map(g_api_ldev, &domain_map);
    }
    else
    {
        ret = ctc_qos_set_domain_map(&domain_map);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_show_qos_domain,
        ctc_cli_qos_show_qos_domain_cmd,
        "show qos (domain DOAMIN) type (cos-map-pri(cos COS_VALUE (dei DEI|))|ip-prec-map-pri(ip-prec IP_PREC) \
        |dscp-map-pri(dscp DSCP_VAlUE (ecn ECN|))|exp-map-pri(exp EXP_VALUE)|pri-map-cos(priority PRI_VALUE color (green | yellow | red)) \
        |pri-map-dscp(priority PRI_VALUE color (green | yellow | red))|pri-map-exp(priority PRI_VALUE color (green | yellow | red)))",
        "Show",
        CTC_CLI_QOS_STR,
        "QoS domain",
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Maping type",
        "Cos map to priority color",
        "Cos",
        "Cos vaule",
        "Dei",
        "Dei vaule",
        "Ip-prec map to priority color",
        "Ip precedence",
        "Ip precedence value",
        "Dscp map to priority color",
        "Dscp",
        "Dscp value",
        "Ecn",
        "ECN value",
        "Exp map to priority color",
        "Exp",
        "Exp value",
        "Priority color map to cos",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red",
        "Priority color map to dscp",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red",
        "Priority color map to exp",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red")
{
    int32 ret = CLI_SUCCESS;
    uint8 type = 0;
    uint8 index = 0;
    ctc_qos_domain_map_t domain_map;

    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));

    index = CTC_CLI_GET_ARGC_INDEX("domain");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("qos domain", domain_map.domain_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("cos-map-pri");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_IGS_COS_TO_PRI_COLOR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("ip-prec-map-pri");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_IGS_IP_PREC_TO_PRI_COLOR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("dscp-map-pri");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_IGS_DSCP_TO_PRI_COLOR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("exp-map-pri");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_IGS_EXP_TO_PRI_COLOR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("pri-map-cos");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_COS;
    }
    index = CTC_CLI_GET_ARGC_INDEX("pri-map-dscp");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_DSCP;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pri-map-exp");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_EXP;
    }

    domain_map.type = type;

    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);

        index = CTC_CLI_GET_ARGC_INDEX("dei");
        if (0xFF != index)
        {
            /* dei */
            CTC_CLI_GET_UINT8("dei", domain_map.hdr_pri.dot1p.dei, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("dscp", domain_map.hdr_pri.tos.dscp, argv[index + 1]);

        index = CTC_CLI_GET_ARGC_INDEX("ecn");
        if (0xFF != index)
        {
            /* ecn */
            CTC_CLI_GET_UINT8("ecn", domain_map.hdr_pri.tos.ecn, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-prec");
    if (0xFF != index)
    {
        /* ip-prec */
        CTC_CLI_GET_UINT8("ip-prec", domain_map.hdr_pri.ip_prec, argv[index + 1]);
    }


    index = CTC_CLI_GET_ARGC_INDEX("exp");
    if (0xFF != index)
    {
        /* exp */
        CTC_CLI_GET_UINT8("exp", domain_map.hdr_pri.exp, argv[index + 1]);
    }


    /* priority */
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        /* priority */
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }


    /* color */
    index = CTC_CLI_GET_ARGC_INDEX("green");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_GREEN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("yellow");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_YELLOW;
    }

    index = CTC_CLI_GET_ARGC_INDEX("red");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_RED;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_domain_map(g_api_ldev, &domain_map);
    }
    else
    {
        ret = ctc_qos_get_domain_map(&domain_map);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    switch (type)
    {
         case CTC_QOS_DOMAIN_MAP_IGS_COS_TO_PRI_COLOR:
            {
                 ctc_cli_out("ingress cos + dei -> priority + color mapping table\n");
                 ctc_cli_out("-----------------------------------------------------\n");
                 ctc_cli_out("   cos(%d)  +  dei(%d) -> priority(%d)  + color(%d)\n",
                            domain_map.hdr_pri.dot1p.cos, domain_map.hdr_pri.dot1p.dei, domain_map.priority, domain_map.color);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_IGS_IP_PREC_TO_PRI_COLOR:
            {
                ctc_cli_out("ingress ip_prec -> priority + color mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out("    ip_prec(%d) -> priority(%d)  + color(%d)\n",
                            domain_map.hdr_pri.ip_prec, domain_map.priority, domain_map.color);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_IGS_DSCP_TO_PRI_COLOR:
            {
                ctc_cli_out("ingress dscp + ecn -> priority + color mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out("    dscp(%d) + ecn(%d) -> priority(%d)  + color(%d) + new_dscp(%d)\n",
                            domain_map.hdr_pri.tos.dscp, domain_map.hdr_pri.tos.ecn, domain_map.priority, domain_map.color, domain_map.new_dscp);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_IGS_EXP_TO_PRI_COLOR:
            {
                ctc_cli_out("ingress exp -> priority + color mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out("    exp(%d) -> priority(%d)  + color(%d) + new_exp(%d)\n",
                            domain_map.hdr_pri.exp, domain_map.priority, domain_map.color, domain_map.new_dscp);
            }
            break;
         case CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_COS:
            {
                ctc_cli_out("egress  priority + color -> cos  mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out(" priority(%d)  + color(%d)  -> cos(%d) + dei(%d)\n",
                              domain_map.priority, domain_map.color, domain_map.hdr_pri.dot1p.cos, domain_map.hdr_pri.dot1p.dei);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_DSCP:
            {
                ctc_cli_out("egress  priority + color -> dscp  mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out(" priority(%d)  + color(%d)  -> dscp(%d)\n",
                              domain_map.priority, domain_map.color, domain_map.hdr_pri.tos.dscp);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_EXP:
            {
                ctc_cli_out("egress  priority + color -> exp  mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out(" priority(%d)  + color(%d)  -> exp(%d)\n",
                              domain_map.priority, domain_map.color, domain_map.hdr_pri.exp);
            }
            break;

    }

    return ret;
}

CTC_CLI(ctc_cli_qos_set_obm_domain_map,
        ctc_cli_qos_set_obm_domain_map_cmd,
        "qos obm-domain DOMAIN map ((cos COS_VALUE |dscp DSCP) to priority PRIORITY",
        CTC_CLI_QOS_STR,
        "OBM domain mapping",
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Mapping",
        "Cos",
        "<0-7>",
        "Dscp",
        "<0-63>",
        "To",
        "Priority",
        CTC_CLI_PRIORITY_VALUE)
{
    uint16 index = 0;
    int32 ret = CLI_SUCCESS;
    ctc_qos_domain_map_t domain_map;

    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));

    /* obm domain */
    CTC_CLI_GET_UINT8("obm domain", domain_map.domain_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_OBM_COS_TO_PRI;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.tos.dscp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_OBM_DSCP_TO_PRI;
    }

    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        /* priority */
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_domain_map(g_api_ldev, &domain_map);
    }
    else
    {
        ret = ctc_qos_set_domain_map(&domain_map);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_show_obm_domain,
        ctc_cli_qos_show_obm_domain_cmd,
        "show qos obm-domain DOAMIN type (cos-map-pri cos COS_VALUE|dscp-map-pri dscp DSCP_VAlUE)",
        "Show",
        CTC_CLI_QOS_STR,
        "OBM domain",
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Maping type",
        "Cos map to priority",
        "Cos",
        "Cos value",
        "Dscp map to priority",
        "Dscp",
        "Dscp value")
{
    uint16 index = 0;
    int32 ret = CLI_SUCCESS;
    ctc_qos_domain_map_t domain_map;

    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));

    /* obm domain */
    CTC_CLI_GET_UINT8("qos domain", domain_map.domain_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_OBM_COS_TO_PRI;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.tos.dscp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_OBM_DSCP_TO_PRI;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_domain_map(g_api_ldev, &domain_map);
    }
    else
    {
        ret = ctc_qos_get_domain_map(&domain_map);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    switch(domain_map.type)
    {
        case CTC_QOS_DOMAIN_MAP_OBM_COS_TO_PRI:
        {
            ctc_cli_out("obm cos -> priority mapping table\n");
            ctc_cli_out("-----------------------------------------------------\n");
            ctc_cli_out("    cos(%d) -> priority(%d)\n", domain_map.hdr_pri.dot1p.cos, domain_map.priority);
            break;
        }
        case CTC_QOS_DOMAIN_MAP_OBM_DSCP_TO_PRI:
        {
            ctc_cli_out("obm dscp -> priority mapping table\n");
            ctc_cli_out("-----------------------------------------------------\n");
            ctc_cli_out("    dscp(%d) -> priority(%d)\n", domain_map.hdr_pri.tos.dscp, domain_map.priority);
            break;
        }
    }

    return ret;
}

#define queue_cli ""
CTC_CLI(ctc_cli_qos_set_queue_flush,
        ctc_cli_qos_set_queue_flush_cmd,
        "qos queue " CTC_CLI_QOS_QUEUE_ID_STR " flush",
        CTC_CLI_QOS_STR,
        "QoS Queue",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Flush pkt")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    que_cfg.type = CTC_QOS_QUEUE_CFG_FLUSH;

    _ctc_cli_qos_queue_id_parser(vty, &que_cfg.value.cfg.queue, &argv[0], argc);

    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_queue_pri_map,
        ctc_cli_qos_set_queue_pri_map_cmd,
        "qos queue (priority-mapping PRIORITY COLOR) to (qsel QSEL) (drop-prec DROP_PREC) (rep-qsel REPQSEL |) (non-uc|)",
        CTC_CLI_QOS_STR,
        "QoS Queue",
        "Priority Mapping",
        CTC_CLI_PRIORITY_VALUE,
        CTC_CLI_COLOR_VALUE,
        "To",
        "Queue select",
        CTC_CLI_QOS_QUEUE_VAL,
        "Drop precedence",
        CTC_CLI_QOS_DROP_PRECEDENCE,
        "Replicaion queue select",
        "Replicaion queue id",
        "Non-uc traffic")
{
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    que_cfg.type = CTC_QOS_QUEUE_CFG_PRI_MAP;

    index = CTC_CLI_GET_ARGC_INDEX("priority-mapping");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("priority", que_cfg.value.pri_map.priority, argv[index + 1]);

        CTC_CLI_GET_UINT16("color", que_cfg.value.pri_map.color, argv[index + 2]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("qsel");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("qsel", que_cfg.value.pri_map.queue_select, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("drop-prec");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("drop-prec", que_cfg.value.pri_map.drop_precedence, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("rep-qsel");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("rep-qsel", que_cfg.value.pri_map.rep_queue_select, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("non-uc");
    if (0xFF != index)
    {
        que_cfg.value.pri_map.non_uc = 1;
    }

    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}
CTC_CLI(ctc_cli_qos_get_queue_pri_map,
        ctc_cli_qos_get_queue_pri_map_cmd,
        "show qos queue (priority-mapping PRIORITY COLOR) (non-uc|)",
        "Show",
        CTC_CLI_QOS_STR,
        "QoS Queue",
        "Priority Mapping",
        CTC_CLI_PRIORITY_VALUE,
        CTC_CLI_COLOR_VALUE,
        "Non-uc traffic")
{
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    que_cfg.type = CTC_QOS_QUEUE_CFG_PRI_MAP;
    index = CTC_CLI_GET_ARGC_INDEX("priority-mapping");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("priority", que_cfg.value.pri_map.priority, argv[index + 1]);
        CTC_CLI_GET_UINT8("color", que_cfg.value.pri_map.color, argv[index + 2]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("non-uc");
    if (0xFF != index)
    {
        que_cfg.value.pri_map.non_uc = 1;
    }
    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_get_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_get_queue(&que_cfg);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("Queue-select   :%d\n",que_cfg.value.pri_map.queue_select);
    ctc_cli_out("Drop-precedence:%d\n",que_cfg.value.pri_map.drop_precedence);
    ctc_cli_out("Rep-que-select :%d\n",que_cfg.value.pri_map.rep_queue_select);
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_port_queue_class,
        ctc_cli_qos_set_port_queue_class_cmd,
        "qos schedule queue-class" CTC_CLI_QOS_QUEUE_ID_STR "(confirm-class CFMCLASS | exceed-class ECDCLASS)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue class",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Confirm green class",
        CTC_CLI_QOS_CLASS_VAL,
        "Exceed yellow class",
        CTC_CLI_QOS_CLASS_VAL)
{
    uint8  queue_class = 0;
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));

	sched_param.type = CTC_QOS_SCHED_QUEUE;

    _ctc_cli_qos_queue_id_parser(vty, &sched_param.sched.queue_sched.queue, &argv[0], argc);

    index = CTC_CLI_GET_ARGC_INDEX("confirm-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_CLASS;
        CTC_CLI_GET_UINT8_RANGE("confirm class", queue_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        sched_param.sched.queue_sched.confirm_class = queue_class;

    }

    index = CTC_CLI_GET_ARGC_INDEX("exceed-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_EXCEED_CLASS;
        CTC_CLI_GET_UINT8_RANGE("exceed class", queue_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        sched_param.sched.queue_sched.exceed_class = queue_class;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_port_group_class_priority,
        ctc_cli_qos_set_port_group_class_priority_cmd,
        "qos schedule pri-propagation" CTC_CLI_QOS_QUEUE_ID_STR "(queue-class CLASS) (priority PRIORITY)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue class propagation to Priority",
         CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Queue class",
        CTC_CLI_QOS_CLASS_VAL,
        "Priority",
        "Value <0-3>")
{
    uint32 gport = 0;
    uint16 service_id = 0;
    uint8  queue_class = 0;
    uint8  priority = 0;
    uint8  index = 0;

    int32 ret = CLI_SUCCESS;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.sched.group_sched.group_type = 0;
    sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;


    /* service id */
    index = CTC_CLI_GET_ARGC_INDEX("service-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("service-id", service_id, argv[index + 1]);
        sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_SERVICE_INGRESS;
        sched_param.sched.group_sched.queue.service_id = service_id;

    }

    /* port */
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", gport, argv[index + 1]);
        sched_param.sched.group_sched.queue.gport = gport;
        sched_param.sched.group_sched.queue.queue_id = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        /* queue-id */
        CTC_CLI_GET_UINT16("queue-id", sched_param.sched.group_sched.queue.queue_id, argv[index + 1]);
    }

   index = CTC_CLI_GET_ARGC_INDEX("reason-id");
    if (0xFF != index)
    {
        /* reason id */
        CTC_CLI_GET_UINT32("reason-id", gport, argv[index+1]);
        sched_param.sched.group_sched.queue.cpu_reason = gport;
	    sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
    }

    /* replication queue */
    index = CTC_CLI_GET_ARGC_INDEX("rep");
    if (0xFF != index)
    {
        sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_REP;
    }

    /* queue class */
    index = CTC_CLI_GET_ARGC_INDEX("queue-class");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("queue-class", queue_class, argv[index + 1]);
    }


    /* queue class priority*/
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("priority", priority, argv[index + 1]);
    }


    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_CLASS;
    sched_param.sched.group_sched.service_id = service_id;
    sched_param.sched.group_sched.gport = gport;
    sched_param.sched.group_sched.queue_class = queue_class;
    sched_param.sched.group_sched.class_priority = priority;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_set_queue_wdrr_weight,
        ctc_cli_qos_set_queue_wdrr_weight_cmd,
        "qos schedule queue-wdrr (service-id SERVICE |) (port GPHYPORT_ID)  (confirm-class| exceed-class) \
    (wdrr-weight (WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT | array [ARRAY]) |queue-id QUEUE_ID weight WEIGHT)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue wdrr",
        CTC_CLI_QOS_SERVICE_STR,
        CTC_CLI_QOS_SERVICE_VAL,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Confirm green class weight",
        "Exceed yellow class weight",
        "Config WDRR weight",
        "Weight of queue 0, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 1, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 2, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 3, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 4, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 5, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 6, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 7, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "weight array",
        "weight array value",
        "Queue id",
        CTC_CLI_QOS_QUEUE_VAL,
        "Config WDRR weight",
        CTC_CLI_QOS_WDRR_WEIGHT_VAL)
{
    uint32 gport = 0;
    uint16 weight = 0;
    uint16 service_id = 0;
    int8   qid = 0;
    int32  ret = 0;
    uint16 index = 0;
    uint8 is_confirm_class = 0;
    ctc_qos_sched_t sched_param;
    uint32 array_cnt = CTC_QUEUE_NUM_PER_PORT;
    uint16 weight_array[CTC_QUEUE_NUM_PER_PORT] = {1,1,1,1,1,1,1,1,1,1,1,1};
    uint8 is_array = 0;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));

    sched_param.type = CTC_QOS_SCHED_QUEUE;
    sched_param.sched.queue_sched.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;


    /* service id */
    index = CTC_CLI_GET_ARGC_INDEX("service-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("service-id", service_id, argv[index + 1]);
        sched_param.sched.queue_sched.queue.queue_type = CTC_QUEUE_TYPE_SERVICE_INGRESS;
        sched_param.sched.queue_sched.queue.service_id = service_id;
    }

    /* port */
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", gport, argv[index + 1]);
        sched_param.sched.queue_sched.queue.gport = gport;
        if (CTC_GPORT_TYPE(gport) == CTC_GPORT_TYPE_DMA)
        {
            sched_param.sched.queue_sched.queue.queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("confirm-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_WEIGHT;
        is_confirm_class = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("exceed-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_EXCEED_WEIGHT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("array");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16_ARRAY("array", weight_array, &array_cnt, argv[index+1], ret);
        is_array = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("wdrr-weight");
    if (0xFF != index)
    {
        /* weight values */
        for (qid = 0; qid < CTC_QUEUE_NUM_PER_PORT; qid++)
        {
            if (8 > qid && !is_array)
            {
                CTC_CLI_GET_UINT16_RANGE("weight", weight_array[qid], argv[qid + index + 1], 0, CTC_MAX_UINT16_VALUE);
            } 
            else if (!is_array) 
            {
                break;
            }
            
            sched_param.sched.queue_sched.queue.queue_id = qid;

            if (is_confirm_class)
            {
                sched_param.sched.queue_sched.confirm_weight = weight_array[qid];
            }
            else
            {
                sched_param.sched.queue_sched.exceed_weight = weight_array[qid];
            }

            if(g_ctcs_api_en)
            {
                 ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
            }
            else
            {
                ret = ctc_qos_set_sched(&sched_param);
            }
            if (ret < 0)
            {
                ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
                return CLI_ERROR;
            }

            /*ctc_cli_update_queue_drop_thrd(vty, &sched_param.sched.queue_sched.queue,weight);*/

        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8_RANGE("queueId", qid, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        CTC_CLI_GET_UINT16_RANGE("weight", weight, argv[index + 3], 0, CTC_MAX_UINT16_VALUE);

        sched_param.sched.queue_sched.queue.queue_id = qid;
        if (is_confirm_class)
        {
            sched_param.sched.queue_sched.confirm_weight = weight;
        }
        else
        {
            sched_param.sched.queue_sched.exceed_weight = weight;
        }

        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
        }
        else
        {
            ret = ctc_qos_set_sched(&sched_param);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

        /*ctc_cli_update_queue_drop_thrd(vty, &sched_param.sched.queue_sched.queue, weight);*/
    }

    return CLI_SUCCESS;
}
CTC_CLI(ctc_cli_qos_set_queue_wdrr_cpu_reason_weight,
        ctc_cli_qos_set_queue_wdrr_cpu_reason_weight_cmd,
        "qos schedule queue-wdrr (reason-id REASON | rep queue-id QUEUE_ID) (confirm-class| exceed-class) (weight WEIGHT)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue wdrr",
        "Cpu reason",
        "Cpu reason id",
        "Replication queue",
        "Queue id",
        CTC_CLI_QOS_QUEUE_VAL,
        "Confirm green class weight",
        "Exceed yellow class weight",
        "Config WDRR weight",
        CTC_CLI_QOS_WDRR_WEIGHT_VAL)
{
    uint32 gport = 0;
    uint16 weight = 0;


    int32  ret = 0;
    uint16 index = 0;
    uint8 is_confirm_class = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));

    sched_param.type = CTC_QOS_SCHED_QUEUE;

    index = CTC_CLI_GET_ARGC_INDEX("reason-id");
    if (0xFF != index)
    {
        /* port */
        CTC_CLI_GET_UINT32("reason-id", gport, argv[index+1]);
        sched_param.sched.queue_sched.queue.queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
        sched_param.sched.queue_sched.queue.cpu_reason = gport;
    }

    index = CTC_CLI_GET_ARGC_INDEX("rep");
    if (0xFF != index)
    {
        /* replication queue id */
        CTC_CLI_GET_UINT32("queue-id", gport, argv[index+2]);
        sched_param.sched.queue_sched.queue.queue_type = CTC_QUEUE_TYPE_REP;
        sched_param.sched.queue_sched.queue.queue_id = gport;
    }

    index = CTC_CLI_GET_ARGC_INDEX("confirm-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_WEIGHT;
        is_confirm_class = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("exceed-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_EXCEED_WEIGHT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("weight");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16_RANGE("weight", weight, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);

        if (is_confirm_class)
        {
            sched_param.sched.queue_sched.confirm_weight = weight;
        }
        else
        {
            sched_param.sched.queue_sched.exceed_weight = weight;
        }

        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
        }
        else
        {
            ret = ctc_qos_set_sched(&sched_param);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

        /*ctc_cli_update_queue_drop_thrd(vty, &sched_param.sched.queue_sched.queue, weight);*/
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_set_group_wdrr_weight,
        ctc_cli_qos_set_group_wdrr_weight_cmd,
        "qos schedule group-wdrr" CTC_CLI_QOS_QUEUE_ID_STR "(priority PRIORITY|)(queue-class CLASS|)(weight WEIGHT)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Group",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Parent Group priority",
        "Priority value",
        "Queue class",
        CTC_CLI_QOS_CLASS_VAL,
        "Config WDRR weight",
        CTC_CLI_QOS_WDRR_WEIGHT_VAL)
{
    int32  ret = 0;
    uint16 index = 0;
    uint8 u8_temp_value = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));

    sched_param.sched.group_sched.group_type = 0;
    sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;

    _ctc_cli_qos_queue_id_parser(vty, &sched_param.sched.group_sched.queue, &argv[0], argc);

    index = CTC_CLI_GET_ARGC_INDEX("rep");
    if (0xFF != index)
    {
        /* replication queue */
        sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_REP;
    }

    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        /* class priority */
        CTC_CLI_GET_UINT8_RANGE("class-priority", u8_temp_value, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        sched_param.sched.group_sched.class_priority = u8_temp_value;
        sched_param.sched.group_sched.group_type = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-class");
    if (0xFF != index)
    {
        /* queue class */
        CTC_CLI_GET_UINT8_RANGE("queue-class", u8_temp_value, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        sched_param.sched.group_sched.queue_class = u8_temp_value;
    }

    index = CTC_CLI_GET_ARGC_INDEX("weight");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8_RANGE("weight", u8_temp_value, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        sched_param.sched.group_sched.weight = u8_temp_value;
    }

    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_WEIGHT;

    if(g_ctcs_api_en)
    {
         ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }
    if (ret < 0)
   {
       ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
       return CLI_ERROR;
   }


    return CLI_SUCCESS;
}




CTC_CLI(ctc_cli_qos_set_queue_wdrr_weight_mtu,
        ctc_cli_qos_set_queue_wdrr_weight_mtu_cmd,
        "qos schedule wdrr-weight-mtu MTU",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Set queue wdrr weight mtu",
        "<1-0xFFFF>")
{
    uint32 mtu = 0;
    int32  ret = CLI_SUCCESS;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    que_cfg.type = CTC_QOS_QUEUE_CFG_SCHED_WDRR_MTU;

    /* mtu */
    CTC_CLI_GET_UINT16_RANGE("mtu", mtu, argv[0], 0, CTC_MAX_UINT16_VALUE);
    que_cfg.value.value_32 = mtu;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;

}


CTC_CLI(ctc_cli_qos_set_schedule_wrr_en,
        ctc_cli_qos_set_schedule_wrr_en_cmd,
        "qos schedule wrr (enable|disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "WRR Schedule",
        "Enable",
        "Disable")
{
    ctc_qos_glb_cfg_t glb_cfg;
    int32 ret = CLI_SUCCESS;
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_SCH_WRR_EN;

    if (CLI_CLI_STR_EQUAL("enable", 0))
    {
        glb_cfg.u.value = 1;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_port_sub_group_id,
        ctc_cli_qos_set_port_sub_group_id_cmd,
        "qos schedule (port GPHYPORT_ID )(queue-class CLASS sub-group GROUP_ID | sub-group GROUP_ID weight WEIGHT)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Queue class",
        CTC_CLI_QOS_CLASS_VAL,
        "Sub group id",
        "Group id value",
        "Sub group id",
        "Group id value",
        "Config WDRR weight",
        CTC_CLI_QOS_WDRR_WEIGHT_VAL)
{
    uint32 gport = 0;
    uint8  queue_class = 0;
    uint8  index = 0;

    int32 ret = CLI_SUCCESS;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;

    /* port */
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", gport, argv[index + 1]);
        sched_param.sched.group_sched.queue.gport = gport;
        sched_param.sched.group_sched.queue.queue_id = 0;
    }

    /* queue class */
    index = CTC_CLI_GET_ARGC_INDEX("queue-class");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("queue-class", queue_class, argv[index + 1]);
        sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_SUB_GROUP_ID;
    }

     /* sub group */
    index = CTC_CLI_GET_ARGC_INDEX("sub-group");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("sub-group", sched_param.sched.group_sched.sub_group_id, argv[index + 1]);
    }

     /* weight */
    index = CTC_CLI_GET_ARGC_INDEX("weight");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("weight", sched_param.sched.group_sched.weight, argv[index + 1]);
        sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_SUB_GROUP_WEIGHT;
    }

    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.queue_class = queue_class;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}
CTC_CLI(ctc_cli_qos_show_port_sub_group_id,
        ctc_cli_qos_show_port_sub_group_id_cmd,
        "show qos schedule (port GPHYPORT_ID )(queue-class CLASS)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Queue class",
        CTC_CLI_QOS_CLASS_VAL)
{
    uint32 gport = 0;
    uint8  queue_class = 0;
    uint8  index = 0;

    int32 ret = CLI_SUCCESS;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.sched.group_sched.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;

    /* port */
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", gport, argv[index + 1]);
        sched_param.sched.group_sched.queue.gport = gport;
        sched_param.sched.group_sched.queue.queue_id = 0;
    }

    /* queue class */
    index = CTC_CLI_GET_ARGC_INDEX("queue-class");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("queue-class", queue_class, argv[index + 1]);
        sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_SUB_GROUP_ID;
    }

    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.queue_class = queue_class;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_get_sched(&sched_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\nSub Group Scheduler:\n");
    ctc_cli_out("-------------------------------\n");
    ctc_cli_out("%-12s %-10s %-6s\n", "Queue-Class", "Sub group ID", "Weight");
    ctc_cli_out("%-12d %-10d %-6d\n", sched_param.sched.group_sched.queue_class, sched_param.sched.group_sched.sub_group_id,
                sched_param.sched.group_sched.weight);
    return CLI_SUCCESS;
}
CTC_CLI(ctc_cli_qos_show_sched,
        ctc_cli_qos_show_sched_cmd,
        "show qos schedule (queue|(group class CLASS))" CTC_CLI_QOS_QUEUE_ID_STR "(priority PRIORITY|)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue",
        "Group",
        "Class",
        "Class value",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Parent Group priority",
        "Priority value")
{
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_sched_t sched_param;
    uint8 u8_temp_value = 0;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));

    sched_param.sched.group_sched.group_type = CTC_QOS_SCHED_GROUP_PORT;
    index = CTC_CLI_GET_ARGC_INDEX("queue");
    if (0xFF != index)
    {
        sched_param.type = CTC_QOS_SCHED_QUEUE;
        _ctc_cli_qos_queue_id_parser(vty, &sched_param.sched.queue_sched.queue, &argv[0], argc);
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_EXCEED_CLASS;
    }

    index = CTC_CLI_GET_ARGC_INDEX("group");
    if (0xFF != index)
    {
        index = CTC_CLI_GET_ARGC_INDEX("class");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT8("class", sched_param.sched.group_sched.queue_class, argv[index + 1]);
        }
        _ctc_cli_qos_queue_id_parser(vty, &sched_param.sched.group_sched.queue, &argv[0], argc);

        index = CTC_CLI_GET_ARGC_INDEX("priority");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT8("service-id", u8_temp_value, argv[index + 1]);
            sched_param.sched.group_sched.class_priority = u8_temp_value;
            sched_param.sched.group_sched.group_type = 1;
            
        }
        sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_CLASS;
        sched_param.type = CTC_QOS_SCHED_GROUP;
    }
    if(g_ctcs_api_en)
    {
         ret = ctcs_qos_get_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_get_sched(&sched_param);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if(sched_param.type == CTC_QOS_SCHED_GROUP)
    {
        ctc_cli_out("\nGroup Scheduler:\n");
        ctc_cli_out("-------------------------------\n");
        ctc_cli_out("%-12s %-10s %-6s\n", "Queue-Class", "Class-PRI", "Weight");
        ctc_cli_out("%-12d %-10d %-6d\n", sched_param.sched.group_sched.queue_class, sched_param.sched.group_sched.class_priority,
                    sched_param.sched.group_sched.weight);
    }
    else if(sched_param.type == CTC_QOS_SCHED_QUEUE)
    {
        ctc_cli_out("\nQueue Scheduler:\n");
        ctc_cli_out("-------------------------------\n");
        ctc_cli_out("%-30s: %d \n", "Queue Class(Green)", sched_param.sched.queue_sched.confirm_class);
        ctc_cli_out("%-30s: %d \n", "Weight", sched_param.sched.queue_sched.confirm_weight);
        ctc_cli_out("%-30s: %d \n", "Queue Class(Yellow)", sched_param.sched.queue_sched.exceed_class);
        ctc_cli_out("%-30s: %d \n", "Weight", sched_param.sched.queue_sched.exceed_weight);
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_sch_create_sch_grp,
        ctc_cli_qos_sch_create_sch_grp_cmd,
        "qos schedule create sch-group (group GROUP|) (level LEVEL) ((port GPHYPORT_ID)|" CTC_CLI_QOS_QUEUE_ID_STR"|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Create sch group",
        "Schedule group",
        "Schedule group id",
        "Group id value",
        "Group level",
        "level value",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        CTC_CLI_QOS_QUEUE_ID_DSCP)
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_sched_group_id_t sch_group;

    sal_memset(&sch_group, 0, sizeof(ctc_qos_sched_group_id_t));

    index = CTC_CLI_GET_ARGC_INDEX("group");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("sch-group", sch_group.group_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("level");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("sch-group", sch_group.level, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", sch_group.gport, argv[index + 1]);
    }
    if(sch_group.level == CTC_QOS_SCHED_GROUP_LVL_Q)
    {
        _ctc_cli_qos_queue_id_parser(vty, &sch_group.queue, &argv[0], argc);
    }

    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_create_sched_group(g_api_ldev, &sch_group);
    }
    else
    {
        ret = ctc_qos_create_sched_group(&sch_group);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("==================================\n");
    ctc_cli_out("sch group : 0x%x\n", sch_group.group_id);
    ctc_cli_out("==================================\n");

    return ret;
}


CTC_CLI(ctc_cli_qos_sch_destory_sch_grp,
        ctc_cli_qos_sch_destory_sch_grp_cmd,
        "qos schedule destroy sch-group (group GROUP)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Destroy sch group",
        "Schedule group",
        "Schedule group id",
        "Group id value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_sched_group_id_t sch_group;

    sal_memset(&sch_group, 0, sizeof(ctc_qos_sched_group_id_t));

    index = CTC_CLI_GET_ARGC_INDEX("group");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("sch-group", sch_group.group_id, argv[index + 1]);
    }

    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_destroy_sched_group(g_api_ldev, &sch_group);
    }
    else
    {
        ret = ctc_qos_destroy_sched_group(&sch_group);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_qos_sch_bind_sch_group,
        ctc_cli_qos_sch_bind_sch_group_cmd,
        "qos schedule bind sch-group (child GROUP) (parent GROUP)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Bind",
        "Schedule group",
        "Child Group",
        "Group value",
        "Parent Group",
        "Group value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_GROUP_PARENT_ID;
    sched_param.type = CTC_QOS_SCHED_GROUP;

    index = CTC_CLI_GET_ARGC_INDEX("child");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("sch-group", sched_param.sched.group_sched.group_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("parent");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("sch-group", sched_param.sched.group_sched.parent_id, argv[index + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_sch_bind_sch_group_node,
        ctc_cli_qos_sch_bind_sch_group_node_cmd,
        "qos schedule bind sch-group child GROUP priority PRIORITY",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Bind",
        "Schedule group",
        "Child Group",
        "Group value",
        "Parent Group priority",
        "Priority value")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_CLASS;

    CTC_CLI_GET_UINT32_RANGE("child", sched_param.sched.group_sched.group_id, argv[0], 0, CTC_MAX_UINT32_VALUE);


    CTC_CLI_GET_UINT8_RANGE("priority", sched_param.sched.group_sched.class_priority, argv[1], 0, CTC_MAX_UINT8_VALUE);


    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_sch_set_sch_group_weight,
        ctc_cli_qos_sch_set_sch_group_weight_cmd,
        "qos schedule sch-group GROUP (priority PRIORITY|) (weight WEIGHT)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Schedule group",
        "Group value",
        "Group priority",
        "Priority value",
        "Weight",
        "Weight Value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_CONFIRM_WEIGHT;


    CTC_CLI_GET_UINT32_RANGE("child", sched_param.sched.group_sched.group_id, argv[0], 0, CTC_MAX_UINT32_VALUE);

    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        sched_param.sched.group_sched.group_type = 1;
        CTC_CLI_GET_UINT8("priority", sched_param.sched.group_sched.class_priority, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("weight");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("weight", sched_param.sched.group_sched.weight, argv[index + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_show_qos_sch_group,
        ctc_cli_show_qos_sch_group_cmd,
        "show qos schedule sch-group (group GROUP | port GPHYPORT_ID) (priority PRIORITY|)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Schedule group",
        "Schedule group id",
        "Group value",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Group priority",
        "Priority value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint16 idx = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.type = CTC_QOS_SCHED_GROUP;

    sched_param.sched.group_sched.child_cnt = CTC_SCH_GRP_MAX_CHILD_CNT;
    sched_param.sched.group_sched.child_id_list = (uint32*)mem_malloc(MEM_CLI_MODULE, sizeof(uint32) * CTC_SCH_GRP_MAX_CHILD_CNT);
    if (NULL == sched_param.sched.group_sched.child_id_list)
    {
        return CLI_ERROR;
    }

    index = CTC_CLI_GET_ARGC_INDEX("group");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("group", sched_param.sched.group_sched.group_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("port", sched_param.sched.group_sched.queue.gport, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        sched_param.sched.group_sched.group_type = 1;
        CTC_CLI_GET_UINT32("priority", sched_param.sched.group_sched.class_priority, argv[index + 1]);
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_get_sched(&sched_param);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        mem_free(sched_param.sched.group_sched.child_id_list);
        return CLI_ERROR;
    }

    ctc_cli_out("\nGroup Scheduler:\n");
    ctc_cli_out("-------------------------------\n");
    ctc_cli_out("%-10s %-6s\n", "Class-PRI", "Weight");
    ctc_cli_out("%-10d %-6d\n", sched_param.sched.group_sched.class_priority, sched_param.sched.group_sched.weight);
    ctc_cli_out("parent id : 0x%x\n", sched_param.sched.group_sched.parent_id);
    ctc_cli_out("%s\n", "child id list:");
    ctc_cli_out("----------------------\n");

    for (idx = 0; idx < sched_param.sched.group_sched.child_cnt; idx++)
    {
        ctc_cli_out("%-11u0x%04X\n", idx + 1, sched_param.sched.group_sched.child_id_list[idx]);
    }

    mem_free(sched_param.sched.group_sched.child_id_list);
    sched_param.sched.group_sched.child_id_list = NULL;

    return ret;
}


CTC_CLI(ctc_cli_qos_sch_set_sch_mode,
        ctc_cli_qos_sch_set_sch_mode_cmd,
        "qos schedule sch-mode" CTC_CLI_QOS_QUEUE_ID_STR "(priority PRIORITY|) mode (wdrr | sp)",
        CTC_CLI_QOS_STR,
        "Schedule",
        "Schedule mode",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Priority",
        "Priority value",
        "Schedule mode",
        "Wdrr",
        "Sp")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_GROUP_SCH_MODE;

    _ctc_cli_qos_queue_id_parser(vty, &sched_param.sched.group_sched.queue, &argv[0], argc);

    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        sched_param.sched.group_sched.group_type = 1;
        CTC_CLI_GET_UINT8("priority", sched_param.sched.group_sched.class_priority, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("wdrr");
    if (0xFF != index)
    {
        sched_param.sched.group_sched.mode = CTC_QOS_SCHED_MODE_WDRR;
    }

    index = CTC_CLI_GET_ARGC_INDEX("sp");
    if (0xFF != index)
    {
        sched_param.sched.group_sched.mode = CTC_QOS_SCHED_MODE_SP;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_set_sched(&sched_param);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_show_qos_sch_mode,
        ctc_cli_show_qos_sch_mode_cmd,
        "show qos schedule sch-mode" CTC_CLI_QOS_QUEUE_ID_STR "(priority PRIORITY|)",
        "Show",
        CTC_CLI_QOS_STR,
        "Schedule",
        "Schedule mode",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Priority",
        "Priority value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.type = CTC_QOS_SCHED_GROUP;
    sched_param.sched.group_sched.cfg_type = CTC_QOS_SCHED_CFG_GROUP_SCH_MODE;

    _ctc_cli_qos_queue_id_parser(vty, &sched_param.sched.group_sched.queue, &argv[0], argc);

    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        sched_param.sched.group_sched.group_type = 1;
        CTC_CLI_GET_UINT32("priority", sched_param.sched.group_sched.class_priority, argv[index + 1]);
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_sched(g_api_ldev, &sched_param);
    }
    else
    {
        ret = ctc_qos_get_sched(&sched_param);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        mem_free(sched_param.sched.group_sched.child_id_list);
        return CLI_ERROR;
    }

    ctc_cli_out("--------------------------\n");
    ctc_cli_out("%-20s: %s \n", "Schedul Mode", CTC_QOS_SCHED_MODE_WDRR == sched_param.sched.group_sched.mode?"wdrr":"sp");
    ctc_cli_out("--------------------------\n");

    return ret;
}

#define shape_cli ""

CTC_CLI(ctc_cli_qos_set_port_queue_shape,
        ctc_cli_qos_set_port_queue_shape_cmd,
        "qos shape queue" CTC_CLI_QOS_QUEUE_ID_STR "(none | {cir CIR (cbs CBS|) | pir PIR (pbs PBS|)} (pps-en|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Queue shaping",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Cancel queue shaping",
        CTC_CLI_QOS_PLC_CIR_STR,
        CTC_CLI_QOS_PLC_CIR_VAL,
        CTC_CLI_QOS_PLC_CBS_STR,
        CTC_CLI_QOS_SHAPE_CBS_STR,
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_SHAPE_PBS_STR,
        "PPS enable")

{
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_queue_t shape;
    uint8 index = 0;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));
    sal_memset(&shape, 0, sizeof(shape));

    _ctc_cli_qos_queue_id_parser(vty, &shape.queue, &argv[0], argc);

    qos_shape.type = CTC_QOS_SHAPE_QUEUE;


    index = CTC_CLI_GET_ARGC_INDEX("none");
    if (0xFF != index)
    {
        shape.enable = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cir");
    if (0xFF != index)
    {
        /* cir */
        CTC_CLI_GET_UINT32("cir", shape.cir, argv[index + 1]);
        shape.enable = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cbs");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("cbs", shape.cbs, argv[index + 1]);
    }
    else
    {
        shape.cbs = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pir");
    if (0xFF != index)
    {
        /* cir */
        CTC_CLI_GET_UINT32("pir", shape.pir, argv[index + 1]);
        shape.enable = 1;
    }
    else
    {
        shape.pir = shape.cir;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pbs");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("pbs", shape.pbs, argv[index + 1]);
    }
    else
    {
        shape.pbs = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pps-en");
    if (0xFF != index)
    {
        shape.pps_en = 1;
    }

    sal_memcpy(&qos_shape.shape, &shape, sizeof(shape));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_shape(g_api_ldev, &qos_shape);
    }
    else
    {
        ret = ctc_qos_set_shape(&qos_shape);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_port_shape,
        ctc_cli_qos_set_port_shape_cmd,
        "qos shape port GPHYPORT_ID (none | pir PIR (pbs PBS|) (pps-en|) (ecn-mark-rate ECN_MARK_RATE|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Cancel port shaping",
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_SHAPE_PBS_STR,
        "PPS enable",
        "Config ecn mark rate",
        CTC_CLI_QOS_PLC_PIR_VAL)
{
    uint32 gport = 0;
    uint8 index  = 0 ;
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_port_t shape;

    sal_memset(&qos_shape, 0, sizeof(ctc_qos_shape_t));
    sal_memset(&shape, 0, sizeof(ctc_qos_shape_port_t));
    /* port */
    CTC_CLI_GET_UINT32("gport", gport, argv[0]);


    shape.gport = gport;
    qos_shape.type = CTC_QOS_SHAPE_PORT;

    if (CLI_CLI_STR_EQUAL("none", 1))
    {
        shape.enable = 0;
    }
    else
    {
        /* rate */
        CTC_CLI_GET_UINT32("rate", shape.pir, argv[2]);
        shape.pbs = 0;
        shape.enable = 1;

        index = CTC_CLI_GET_ARGC_INDEX("pbs");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("pbs", shape.pbs, argv[index+1]);
        }

        index = CTC_CLI_GET_ARGC_INDEX("pps-en");
        if (0xFF != index)
        {
            shape.pps_en = 1;
        }

    }

    index = CTC_CLI_GET_ARGC_INDEX("ecn-mark-rate");
    if (0xFF != index)
    {
        /* ecn-mark-rate */
        CTC_CLI_GET_UINT32("ecn mark rate", shape.ecn_mark_rate, argv[index + 1]);
    }

    sal_memcpy(&qos_shape.shape, &shape, sizeof(ctc_qos_shape_port_t));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_shape(g_api_ldev, &qos_shape);
    }
    else
    {
        ret = ctc_qos_set_shape(&qos_shape);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_set_group_shape,
        ctc_cli_qos_set_group_shape_cmd,
        "qos shape group" "("CTC_CLI_QOS_QUEUE_ID_STR"|(group-id GROUP_ID))" "(none | pir PIR (pbs PBS|) (pps-en|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Group shaping",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Group-id",
        "Value",
        "Cancel port shaping",
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_SHAPE_PBS_STR,
        "PPS enable")
{
    uint32 gport = 0;
    uint16 service_id = 0;
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_group_t shape;
    uint8 index = 0;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));
    sal_memset(&shape, 0, sizeof(shape));

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        /* port */
        CTC_CLI_GET_UINT32("gport", gport, argv[index+1]);
        shape.group_type = CTC_QOS_SCHED_GROUP_PORT;
        shape.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;
        shape.queue.gport = gport;
        shape.queue.queue_id = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        /* queue-id */
        CTC_CLI_GET_UINT16("queue-id", shape.queue.queue_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("reason-id");
    if (0xFF != index)
    {
        /* port */
        CTC_CLI_GET_UINT16("reason-id", shape.queue.cpu_reason, argv[index+1]);
        shape.queue.queue_type = CTC_QUEUE_TYPE_EXCP_CPU;

    }
    shape.gport = gport;

    index = CTC_CLI_GET_ARGC_INDEX("service-id");
    if (0xFF != index)
    {
        /* service id */
        CTC_CLI_GET_UINT16("service-id", service_id, argv[index + 1]);
        shape.service_id = service_id;
        shape.group_type = CTC_QOS_SCHED_GROUP_SERVICE;
        shape.queue.service_id = service_id;
        shape.queue.queue_type = CTC_QUEUE_TYPE_SERVICE_INGRESS;
    }

    index = CTC_CLI_GET_ARGC_INDEX("group-id");
    if (0xFF != index)
    {
        /* service id */
        CTC_CLI_GET_UINT32("group-id", shape.group_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("none");
    if (0xFF != index)
    {
        shape.enable = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pir");
    if (0xFF != index)
    {
        /* cir */
        CTC_CLI_GET_UINT32("pir", shape.pir, argv[index + 1]);
        shape.pbs = 0;
        shape.enable = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pbs");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("pbs", shape.pbs, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("pps-en");
    if (0xFF != index)
    {
        shape.pps_en = 1;
    }

    qos_shape.type = CTC_QOS_SHAPE_GROUP;
    sal_memcpy(&qos_shape.shape, &shape, sizeof(shape));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_shape(g_api_ldev, &qos_shape);
    }
    else
    {
        ret = ctc_qos_set_shape(&qos_shape);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_set_shape_ipg_en,
        ctc_cli_qos_set_shape_ipg_en_cmd,
        "qos shape ipg (enable|disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Ipg",
        "Enable",
        "Disable")
{
    ctc_qos_glb_cfg_t glb_cfg;
    int32 ret = CLI_SUCCESS;
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_SHAPE_IPG_EN;

    if (CLI_CLI_STR_EQUAL("enable", 0))
    {
        glb_cfg.u.value = 1;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return CLI_SUCCESS;
}



CTC_CLI(ctc_cli_qos_set_reason_shape,
        ctc_cli_qos_set_reason_shape_cmd,
        "qos shape cpu-reason REASON_ID (none | pir PIR)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Cpu reason id",
        "<0-MAX>",
        "Cancel cpu reason shaping",
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL)
{
    uint16 reason_id = 0;
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_queue_t shape;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));
    sal_memset(&shape, 0, sizeof(shape));

    /* reason-id */
    CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[0]);

    shape.queue.cpu_reason = reason_id;
    shape.queue.queue_id = 0;
    shape.queue.queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
    qos_shape.type = CTC_QOS_SHAPE_QUEUE;

    if (CLI_CLI_STR_EQUAL("none", 1))
    {
        shape.enable = 0;
    }
    else
    {
        /* rate */
        CTC_CLI_GET_UINT32("rate", shape.pir, argv[2]);
        shape.pbs = CTC_QOS_SHP_TOKE_THRD_DEFAULT;
        shape.enable = 1;
    }

    sal_memcpy(&qos_shape.shape, &shape, sizeof(shape));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_shape(g_api_ldev, &qos_shape);
    }
    else
    {
        ret = ctc_qos_set_shape(&qos_shape);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_set_queue_pkt_len,
        ctc_cli_qos_set_queue_pkt_len_cmd,
        "qos shape pkt-len-adjust" CTC_CLI_QOS_QUEUE_ID_STR "(pkt-adjust-len LEN)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Packet Length adjust",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Packet adjust len",
        "Value")
{
    uint8 index = 0;
    uint8 adjust_len = 0;
    int32 ret = CLI_SUCCESS;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(que_cfg));

    _ctc_cli_qos_queue_id_parser(vty, &que_cfg.value.pkt.queue, &argv[0], argc);

    index = CTC_CLI_GET_ARGC_INDEX("pkt-adjust-len");
    if (0xFF != index)
    {
        /* queue packet len adjust */
        CTC_CLI_GET_UINT8("pkt-adjust-len", adjust_len, argv[index+1]);
    }

    que_cfg.type = CTC_QOS_QUEUE_CFG_LENGTH_ADJUST;
    que_cfg.value.pkt.adjust_len       = adjust_len;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_show_shape,
        ctc_cli_qos_show_shape_cmd,
        "show qos shape ((port GPHYPORT_ID)|((queue | group)" "((group-id GROUP_ID) |" CTC_CLI_QOS_QUEUE_ID_STR"))))",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Queue shaping",
        "Group shaping",
        "Group id",
        "Group id value",
        CTC_CLI_QOS_QUEUE_ID_DSCP)
{
    int32 ret = CLI_SUCCESS;
    uint32 gport = 0;
    uint16 service_id = 0;
    ctc_qos_shape_t qos_shape;
    uint8 index = 0;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        /* port */
        CTC_CLI_GET_UINT32("gport", gport, argv[index+1]);
        qos_shape.type = CTC_QOS_SHAPE_PORT;
        qos_shape.shape.port_shape.gport = gport;
    }
    index = CTC_CLI_GET_ARGC_INDEX("queue");
    if (0xFF != index)
    {
        _ctc_cli_qos_queue_id_parser(vty, &qos_shape.shape.queue_shape.queue, &argv[0], argc);
        qos_shape.type = CTC_QOS_SHAPE_QUEUE;
    }
    index = CTC_CLI_GET_ARGC_INDEX("group");
    if (0xFF != index)
    {
        _ctc_cli_qos_queue_id_parser(vty, &qos_shape.shape.group_shape.queue, &argv[0], argc);
        qos_shape.type = CTC_QOS_SHAPE_GROUP;
        index = CTC_CLI_GET_ARGC_INDEX("service-id");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT16("service-id", service_id, argv[index + 1]);
            qos_shape.shape.group_shape.group_type = CTC_QOS_SCHED_GROUP_SERVICE;
            qos_shape.shape.group_shape.service_id = service_id;
        }
        index = CTC_CLI_GET_ARGC_INDEX("port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("gport", qos_shape.shape.group_shape.gport, argv[index + 1]);
        }

        index = CTC_CLI_GET_ARGC_INDEX("group-id");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("group-id", qos_shape.shape.group_shape.group_id, argv[index + 1]);
        }
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_shape(g_api_ldev, &qos_shape);
    }
    else
    {
        ret = ctc_qos_get_shape(&qos_shape);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if(qos_shape.type == CTC_QOS_SHAPE_QUEUE)
    {
        ctc_cli_out("\nQueue shape:\n");
        ctc_cli_out("%-10s %-15s %-15s %-15s %-15s %-15s\n","shp-en", "cir(kbps/pps)", "cbs(kb/pkt)","pir(kbps/pps)", "pbs(kb/pkt)", "pps-en");
        ctc_cli_out("-----------------------------------------------------------------\n");
        ctc_cli_out("%-10d %-15u %-15u %-15u %-15u %-15u\n",qos_shape.shape.queue_shape.enable,qos_shape.shape.queue_shape.cir,
                    qos_shape.shape.queue_shape.cbs, qos_shape.shape.queue_shape.pir, 
                    qos_shape.shape.queue_shape.pbs, qos_shape.shape.queue_shape.pps_en);
    }
    else if(qos_shape.type == CTC_QOS_SHAPE_PORT)
    {
        ctc_cli_out("\nPort shape:\n");
        ctc_cli_out("%-10s %-15s %-15s %-15s %-15s\n","shp-en","pir(kbps/pps)", "pbs(kb/pkt)", "ecn-mark-rate", "pps-en");
        ctc_cli_out("-----------------------------------------------------------------\n");
        ctc_cli_out("%-10d %-15u %-15u %-15u %-15u\n",qos_shape.shape.port_shape.enable, qos_shape.shape.port_shape.pir, qos_shape.shape.port_shape.pbs,
                    qos_shape.shape.port_shape.ecn_mark_rate, qos_shape.shape.port_shape.pps_en);
    }
    else if(qos_shape.type == CTC_QOS_SHAPE_GROUP)
    {
        ctc_cli_out("\nGroup shape:\n");
        ctc_cli_out("%-10s %-15s %-15s %-15s\n","shp-en","pir(kbps/pps)", "pbs(kb/pkt)", "pps-en");
        ctc_cli_out("-----------------------------------------------------------------\n");
        ctc_cli_out("%-10d %-15u %-15u %-15u\n",qos_shape.shape.group_shape.enable, qos_shape.shape.group_shape.pir, 
                    qos_shape.shape.group_shape.pbs, qos_shape.shape.group_shape.pps_en);
    }

    return ret;
}


CTC_CLI(ctc_cli_qos_set_group_node_shape,
        ctc_cli_qos_set_group_node_shape_cmd,
        "qos shape group (group-id GROUP_ID group-node GROUP_NODE) (none | {cir CIR (cbs CBS|) | pir PIR (pbs PBS|)} (pps-en|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Group shaping",
        "Group id",
        "Group id value",
        "Group node",
        "Group node value",
        "Cancel queue shaping",
        CTC_CLI_QOS_PLC_CIR_STR,
        CTC_CLI_QOS_PLC_CIR_VAL,
        CTC_CLI_QOS_PLC_CBS_STR,
        CTC_CLI_QOS_SHAPE_CBS_STR,
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_SHAPE_PBS_STR,
        "PPS enable")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_group_t shape;
    uint8 index = 0;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));
    sal_memset(&shape, 0, sizeof(shape));

    index = CTC_CLI_GET_ARGC_INDEX("group-id");
    if (0xFF != index)
    {
        /* service id */
        CTC_CLI_GET_UINT32("group-id", shape.group_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("group-node");
    if (0xFF != index)
    {
        /* service id */
        CTC_CLI_GET_UINT32("group-node", shape.class_prio, argv[index + 1]);
        shape.class_prio_valid = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("none");
    if (0xFF != index)
    {
        shape.enable = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cir");
    if (0xFF != index)
    {
        /* cir */
        CTC_CLI_GET_UINT32("cir", shape.cir, argv[index + 1]);
        shape.enable = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cbs");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("cbs", shape.cbs, argv[index + 1]);
    }
    else
    {
        shape.cbs = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pir");
    if (0xFF != index)
    {
        /* cir */
        CTC_CLI_GET_UINT32("pir", shape.pir, argv[index + 1]);
        shape.enable = 1;
    }
    else
    {
        shape.pir = shape.cir;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pbs");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("pbs", shape.pbs, argv[index + 1]);
    }
    else
    {
        shape.pbs = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pps-en");
    if (0xFF != index)
    {
        shape.pps_en = 1;
    }

    qos_shape.type = CTC_QOS_SHAPE_GROUP;
    sal_memcpy(&qos_shape.shape, &shape, sizeof(shape));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_shape(g_api_ldev, &qos_shape);
    }
    else
    {
        ret = ctc_qos_set_shape(&qos_shape);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_get_group_node_shape,
        ctc_cli_qos_get_group_node_shape_cmd,
        "show qos shape group (group-id GROUP_ID group-node GROUP_NODE)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Group shaping",
        "Group id",
        "Group id value",
        "Group node",
        "Group node value")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_group_t shape;
    uint8 index = 0;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));
    sal_memset(&shape, 0, sizeof(shape));

    index = CTC_CLI_GET_ARGC_INDEX("group-id");
    if (0xFF != index)
    {
        /* service id */
        CTC_CLI_GET_UINT32("group-id", shape.group_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("group-node");
    if (0xFF != index)
    {
        /* service id */
        CTC_CLI_GET_UINT32("group-node", shape.class_prio, argv[index + 1]);
        shape.class_prio_valid = 1;
    }

    qos_shape.type = CTC_QOS_SHAPE_GROUP;
    sal_memcpy(&qos_shape.shape, &shape, sizeof(shape));

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_shape(g_api_ldev, &qos_shape);
    }
    else
    {
        ret = ctc_qos_get_shape(&qos_shape);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\nGroup Node shape:\n");
    ctc_cli_out("%-10s %-15s %-15s %-15s %-15s \n", "shp-en", "cir(kbps/pps)", "cbs(kb/pkt)", "pir(kbps/pps)", "pbs(kb/pkt)");
    ctc_cli_out("-----------------------------------------------------------------\n");
    ctc_cli_out("%-10d %-15u %-15u %-15u %-15u\n", qos_shape.shape.group_shape.enable, qos_shape.shape.group_shape.cir, qos_shape.shape.group_shape.cbs,
                qos_shape.shape.group_shape.pir, qos_shape.shape.group_shape.pbs);

    return ret;
}

#define drop_cli ""

CTC_CLI(ctc_cli_qos_get_shape_en,
        ctc_cli_qos_get_shape_en_cmd,
        "show qos shape enable (port | queue | group)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "enable",
        "port shape",
        "queue shape",
        "group shape")
{
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    ctc_cli_out(" Show qos shape enable\n");
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_PORT_SHAPE_EN;
        ctc_cli_out(" ==================================\n");
        ctc_cli_out(" port : ");
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_QUE_SHAPE_EN;
        ctc_cli_out(" ==================================\n");
        ctc_cli_out(" queue : ");
    }

    index = CTC_CLI_GET_ARGC_INDEX("group");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_GROUP_SHAPE_EN;
        ctc_cli_out(" ==================================\n");
        ctc_cli_out(" group : ");
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_get_global_config(&glb_cfg);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    if(glb_cfg.u.value == 1)
    {
        ctc_cli_out("enable\n ");
    }
    else
    {
        ctc_cli_out("disable\n ");
    }

    ctc_cli_out("==================================\n");

    return ret;
}

CTC_CLI(ctc_cli_qos_set_port_queue_drop,
        ctc_cli_qos_set_port_queue_drop_cmd,
        "qos drop (type "CTC_QOS_BUFFER_TYPE_STR"|"CTC_CLI_QOS_QUEUE_ID_STR") \
    (wtd (threshold THRESH1 THRESH2 THRESH3| factor FACTOR1 FACTOR2 FACTOR3) | \
    wred (non-ecn|) min-threshold THRESH1 THRESH2 THRESH3 \
    max-threshold THRESH1 THRESH2 THRESH3 \
    drop-probability PROB1 PROB2 PROB3 \
    (weight WEIGHT|)|) (level-profile LEVEL|) ((ecn-color-threshold ECN_THRD1 ECN_THRD2 ECN_THRD3 (ecn-color-threshold2 ECN_THRD1 ECN_THRD2 ECN_THRD3|) |ecn-threshold ECN_THRD)|) (coexist-mode|)("CTC_CLI_DIR_STR"|)(non-uc |)",
        CTC_CLI_QOS_STR,
        "Config qos drop",
        "Qos buffer type",
        CTC_QOS_BUFFER_TYPE_DESC,
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Weighted tail drop",
        "Drop threshold",
        "Drop threshold for red-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Drop threshold for yellow-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Drop threshold for green-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Drop factor",
        "Drop factor for red-colored packets",
        "Drop factor for yellow-colored packets",
        "Drop factor for green-colored packets",
        "Weighted random early detection",
        "Weighted random early detection non-ecn mode",
        "Minimum threshold",
        "Minimum threshold for red-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Minimum threshold for yellow-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Minimum threshold for green-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Maximum threshold",
        "Maximum threshold for red-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Maximum threshold for yellow-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Maximum threshold for green-colored packets, "CTC_CLI_QOS_DROP_THRESHOLD,
        "Drop probability",
        "Drop probability for red-colored packets, "CTC_CLI_QOS_DROP_PROB_VAL,
        "Drop probability for yellow-colored packets, "CTC_CLI_QOS_DROP_PROB_VAL,
        "Drop probability for green-colored packets, "CTC_CLI_QOS_DROP_PROB_VAL,
        "Weight [GB not support]",
        "WRED weight for computing average queue size, <0-15>",
        "Congestion level drop profile",
        "<0-7>",
        "ECN color mark threshold",
        "Ecn threshod for red-colored should less than max threshold",
        "Ecn threshod for yellow-colored should less than max threshold",
        "Ecn threshod for green-colored should less than max threshold",
        "ECN color mark threshold2",
        "Ecn threshod for red-colored should less than max threshold",
        "Ecn threshod for yellow-colored should less than max threshold",
        "Ecn threshod for green-colored should less than max threshold",
        "ECN mark threshold",
        "Ecn threshod should less than max threshold",
        "WTD and WRED coexist",
        CTC_CLI_DIR_DESC,
         "Non Uc")
{
    uint8  index = 0;
    uint8  level = 0;
    ctc_qos_drop_t drop_param;
    ctc_qos_queue_drop_t drop;
    int32 ret = CLI_SUCCESS;

    sal_memset(&drop_param, 0, sizeof(ctc_qos_drop_t));
    sal_memset(&drop, 0, sizeof(ctc_qos_queue_drop_t));

    CTC_CLI_QOS_DROP_ARRAY_INIT;

    index = CTC_CLI_GET_ARGC_INDEX("type");
    if (0xFF != index)
    {
        _ctc_cli_qos_buffer_type_parser(vty, &drop_param.type, &argv[0], argc);

        index = CTC_CLI_GET_ARGC_INDEX("sc");
        if (0xFF != index)
        {
             CTC_CLI_GET_UINT8("pool", drop_param.pool, argv[index + 1]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("gport", drop_param.gport, argv[index + 1]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("port-sc");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("gport", drop_param.gport, argv[index + 1]);
            CTC_CLI_GET_UINT32("pool", drop_param.pool, argv[index + 2]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("port-prio-class");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("gport", drop_param.gport, argv[index + 1]);
            CTC_CLI_GET_UINT32("prio class", drop_param.prio_class, argv[index + 2]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("queue");
        if (0xFF != index)
        {
            _ctc_cli_qos_queue_id_parser(vty, &drop_param.queue, &argv[0], argc);
        }

        CTC_CLI_DIR_SET(&drop_param.dir);
    }
    else 
    {
        _ctc_cli_qos_queue_id_parser(vty, &drop_param.queue, &argv[0], argc);
    }

    index = CTC_CLI_GET_ARGC_INDEX("non-uc");
    if (0xFF != index)
    {
        drop_param.non_uc = 1;
    }
    
    index = CTC_CLI_GET_ARGC_INDEX("wtd");
    if (0xFF != index)
    {
        drop.mode = CTC_QUEUE_DROP_WTD;
        index = CTC_CLI_GET_ARGC_INDEX("threshold");
        if (0xFF != index)
        {
            /* red threshold */
            CTC_CLI_GET_UINT32_RANGE("red threshold", drop.max_th[0], argv[index + 1], 0, CTC_MAX_UINT32_VALUE);

            /* yellow threshold */
            CTC_CLI_GET_UINT32_RANGE("yellow threshold", drop.max_th[1], argv[index + 2], 0, CTC_MAX_UINT32_VALUE);

            /* green threshold */
            CTC_CLI_GET_UINT32_RANGE("green threshold", drop.max_th[2], argv[index + 3], 0, CTC_MAX_UINT32_VALUE);

            /* critical threshold */
            drop.max_th[3] = 0x44;
        }
        index = CTC_CLI_GET_ARGC_INDEX("factor");
        if (0xFF != index)
        {
            drop.is_dynamic = 1;
            /* red factor */
            CTC_CLI_GET_UINT8_RANGE("red factor", drop.drop_factor[0], argv[index + 1], 0, CTC_MAX_UINT8_VALUE);

            /* yellow factor */
            CTC_CLI_GET_UINT8_RANGE("yellow factor", drop.drop_factor[1], argv[index + 2], 0, CTC_MAX_UINT8_VALUE);

            /* green factor */
            CTC_CLI_GET_UINT8_RANGE("green factor", drop.drop_factor[2], argv[index + 3], 0, CTC_MAX_UINT8_VALUE);

            /* critical factor */
            drop.drop_factor[3] = 7;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("wred");
    if (0xFF != index)
    {
        uint8 index_temp = 0;
    
        drop.mode = CTC_QUEUE_DROP_WRED;

        index_temp = CTC_CLI_GET_ARGC_INDEX("non-ecn");
        if (0xFF != index_temp)
        {
            index = index_temp;
            drop.mode = CTC_QUEUE_DROP_WRED_NON_ECN;
        }

        /* red min-threshold */
        CTC_CLI_GET_UINT32_RANGE("red min-threshold", drop.min_th[0], argv[index + 2], 0, CTC_MAX_UINT32_VALUE);
        /* yellow min-threshold */
        CTC_CLI_GET_UINT32_RANGE("yellow min-threshold", drop.min_th[1], argv[index + 3], 0, CTC_MAX_UINT32_VALUE);
        /* green min-threshold */
        CTC_CLI_GET_UINT32_RANGE("green min-threshold", drop.min_th[2], argv[index + 4], 0, CTC_MAX_UINT32_VALUE);

        /* red max-threshold */
        CTC_CLI_GET_UINT32_RANGE("red max-threshold", drop.max_th[0], argv[index + 6], 0, CTC_MAX_UINT32_VALUE);
        /* yellow max-threshold */
        CTC_CLI_GET_UINT32_RANGE("yellow max-threshold", drop.max_th[1], argv[index + 7], 0, CTC_MAX_UINT32_VALUE);
        /* green max-threshold */
        CTC_CLI_GET_UINT32_RANGE("green max-threshold", drop.max_th[2], argv[index + 8], 0, CTC_MAX_UINT32_VALUE);

        /* red drop probability */
        CTC_CLI_GET_UINT16_RANGE("red drop probability", drop.drop_prob[0], argv[index + 10], 0, CTC_MAX_UINT16_VALUE);
        /* yellow drop probability */
        CTC_CLI_GET_UINT16_RANGE("yellow drop probability", drop.drop_prob[1], argv[index + 11], 0, CTC_MAX_UINT16_VALUE);
        /* green drop probability */
        CTC_CLI_GET_UINT16_RANGE("green drop probability", drop.drop_prob[2], argv[index + 12], 0, CTC_MAX_UINT16_VALUE);

        /* critical threshold */
        drop.max_th[3] = 0x44;
        drop.drop_prob[3] = 10;
    }

    index = CTC_CLI_GET_ARGC_INDEX("weight");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("wred weight", drop.weight, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ecn-threshold");
    if (0xFF != index)
    {
        /*ecn mark threshold*/
        CTC_CLI_GET_UINT16("ecn threshold", drop.ecn_mark_th, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("ecn-color-threshold");
    if (0xFF != index)
    {
        /*red ecn mark threshold*/
        CTC_CLI_GET_UINT32("red ecn threshold", drop.ecn_th[0], argv[index + 1]);
        /*yellow mark threshold*/
        CTC_CLI_GET_UINT32("yellow ecn threshold", drop.ecn_th[1], argv[index + 2]);
        /*green mark threshold*/
        CTC_CLI_GET_UINT32("green ecn threshold", drop.ecn_th[2], argv[index + 3]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ecn-color-threshold2");
    if (0xFF != index)
    {
        /*red ecn mark threshold*/
        CTC_CLI_GET_UINT32("red ecn threshold2", drop.ecn_th2[0], argv[index + 1]);
        /*yellow mark threshold*/
        CTC_CLI_GET_UINT32("yellow ecn threshold2", drop.ecn_th2[1], argv[index + 2]);
        /*green mark threshold*/
        CTC_CLI_GET_UINT32("green ecn threshold2", drop.ecn_th2[2], argv[index + 3]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("coexist-mode");
    if (0xFF != index)
    {
        drop.is_coexist = 1;
    }

    sal_memcpy(&drop_param.drop, &drop, sizeof(ctc_qos_queue_drop_t));

    index = CTC_CLI_GET_ARGC_INDEX("level-profile");
    if (0xFF != index)
    {
        /* when use level profile, only set global varible */
        CTC_CLI_GET_UINT8_RANGE("level", level, argv[index + 1], 0, 7);
        if(level < CTC_RESRC_MAX_CONGEST_LEVEL_NUM)
        {
        sal_memcpy(&g_qos_drop_array[level], &drop_param, sizeof(drop_param));
        }
    }
    else
    {
        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_set_drop_scheme(g_api_ldev, &drop_param);
        }
        else
        {
            ret = ctc_qos_set_drop_scheme(&drop_param);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_get_port_queue_drop,
        ctc_cli_qos_get_port_queue_drop_cmd,
        "show qos drop (type "CTC_QOS_BUFFER_TYPE_STR"|"CTC_CLI_QOS_QUEUE_ID_STR")("CTC_CLI_DIR_STR"|)(non-uc |)(level-profile|)",
        "Show",
        CTC_CLI_QOS_STR,
        "Config qos drop",
        "Qos buffer type",
        CTC_QOS_BUFFER_TYPE_DESC,
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        CTC_CLI_DIR_DESC,
        "Non Uc",
        "Congestion level drop profile")
{
    uint8 index = 0;
    uint8 non_ecn = 0;
    ctc_qos_drop_t drop_param;
    ctc_qos_drop_t tempdrop_param;
    int32 ret = CLI_SUCCESS;
    ctc_qos_resrc_t resrc;

    sal_memset(&drop_param, 0, sizeof(ctc_qos_drop_t));
    sal_memset(&tempdrop_param, 0, sizeof(ctc_qos_drop_t));
    sal_memset(&resrc, 0, sizeof(ctc_qos_resrc_t));

    index = CTC_CLI_GET_ARGC_INDEX("type");
    if (0xFF != index)
    {
        _ctc_cli_qos_buffer_type_parser(vty, &drop_param.type, &argv[0], argc);

        index = CTC_CLI_GET_ARGC_INDEX("sc");
        if (0xFF != index)
        {
             CTC_CLI_GET_UINT8("pool", drop_param.pool, argv[index + 1]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("gport", drop_param.gport, argv[index + 1]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("port-sc");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("gport", drop_param.gport, argv[index + 1]);
            CTC_CLI_GET_UINT8("pool", drop_param.pool, argv[index + 2]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("port-prio-class");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("gport", drop_param.gport, argv[index + 1]);
            CTC_CLI_GET_UINT8("prio class", drop_param.prio_class, argv[index + 2]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("queue");
        if (0xFF != index)
        {
            _ctc_cli_qos_queue_id_parser(vty, &drop_param.queue, &argv[0], argc);
        }

        CTC_CLI_DIR_SET(&drop_param.dir);
    }
    else 
    {
        _ctc_cli_qos_queue_id_parser(vty, &drop_param.queue, &argv[0], argc);
        drop_param.type = CTC_QOS_BUFFER_QUEUE;
    }
    
    index = CTC_CLI_GET_ARGC_INDEX("non-uc");
    if (0xFF != index)
    {
        drop_param.non_uc = 1;
    }

    resrc.cfg_type = CTC_QOS_RESRC_CFG_QUEUE_DROP;
    sal_memcpy(&tempdrop_param, &drop_param, sizeof(ctc_qos_drop_t));
    sal_memcpy(resrc.u.queue_drop, &drop_param, sizeof(ctc_qos_drop_t));
    drop_param.drop.mode = MAX_CTC_QUEUE_DROP;
    ctc_cli_out("%-10s\n", "Queue drop information");
    ctc_cli_out("----------------\n");

    index = CTC_CLI_GET_ARGC_INDEX("level-profile");
    if (0xFF != index)
    {
        if(g_ctcs_api_en)
        {
            ret = ctcs_qos_get_resrc(g_api_ldev, &resrc);
        }
        else
        {
            ret = ctc_qos_get_resrc(&resrc);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        if(resrc.u.queue_drop[0].drop.mode == 1)
        {
            ctc_cli_out("%-30s: %s\n", "Drop Mode", "WRED");
            ctc_cli_out("%-30s: %u\n", "WTD and WRED coexist ", resrc.u.queue_drop[0].drop.is_coexist);
            for (index = 0; index < CTC_RESRC_MAX_CONGEST_LEVEL_NUM; index++)
            {
                ctc_cli_out("Congest:%d %-19s : %-8u%-8u%-8u%-8u\n",
                             index, "MaxThrd", resrc.u.queue_drop[index].drop.max_th[0],
                             resrc.u.queue_drop[index].drop.max_th[1],
                             resrc.u.queue_drop[index].drop.max_th[2],
                             resrc.u.queue_drop[index].drop.max_th[3]);
                ctc_cli_out("Congest:%d %-19s : %-8u%-8u%-8u%-8u\n",
                             index, "MinThrd", resrc.u.queue_drop[index].drop.min_th[0],
                             resrc.u.queue_drop[index].drop.min_th[1],
                             resrc.u.queue_drop[index].drop.min_th[2],
                             resrc.u.queue_drop[index].drop.min_th[3]);
                ctc_cli_out("Congest:%d %-19s : %-8u%-8u%-8u%-8u\n",
                             index, "DropProb", resrc.u.queue_drop[index].drop.drop_prob[0],
                             resrc.u.queue_drop[index].drop.drop_prob[1],
                             resrc.u.queue_drop[index].drop.drop_prob[2],
                             resrc.u.queue_drop[index].drop.drop_prob[3]);
            }
        }
        else
        {
            ctc_cli_out("%-30s: %s\n", "Drop Mode", "WTD");
            ctc_cli_out("%-30s: %u\n", "WTD and WRED coexist ", resrc.u.queue_drop[0].drop.is_coexist);
            for (index = 0; index < CTC_RESRC_MAX_CONGEST_LEVEL_NUM; index++)
            {
                ctc_cli_out("Congest:%d %-19s : %-8u%-8u%-8u%-8u\n",
                             index, "DropThrd", resrc.u.queue_drop[index].drop.max_th[0],
                             resrc.u.queue_drop[index].drop.max_th[1],
                             resrc.u.queue_drop[index].drop.max_th[2],
                             resrc.u.queue_drop[index].drop.max_th[3]);
                ctc_cli_out("Congest:%d %-19s : %-8u%-8u%-8u%-8u\n",
                             index, "EcnThrdColor", resrc.u.queue_drop[index].drop.ecn_th[0],
                             resrc.u.queue_drop[index].drop.ecn_th[1],
                             resrc.u.queue_drop[index].drop.ecn_th[2],
                             resrc.u.queue_drop[index].drop.ecn_th[3]);
                ctc_cli_out("Congest:%d %-19s : %-8u\n",
                             index, "EcnThrd", resrc.u.queue_drop[index].drop.ecn_mark_th);

            }
        }
    }
    else
    {
        drop_param.drop.mode = CTC_QUEUE_DROP_WTD;
        /*1. get wtd drop param*/
        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_get_drop_scheme(g_api_ldev, &drop_param);
        }
        else
        {
            ret = ctc_qos_get_drop_scheme(&drop_param);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

        /*2. get ecn threhold if type is sc_ingress or porttc_egress*/
        if ((CTC_QOS_BUFFER_PORT_PRIO_CLASS == drop_param.type && CTC_EGRESS == drop_param.dir) || \
            (CTC_QOS_BUFFER_SC == drop_param.type ) )
        {
            ctc_cli_out("ecn threhold off : %8u\n", drop_param.drop.ecn_th[0]);
            ctc_cli_out("ecn threhold on  : %8u\n", drop_param.drop.ecn_th2[0]);
            
            return CLI_SUCCESS;
        }
        
        _ctc_cli_queue_drop_wtd_show(vty, drop_param);

        if (CTC_QOS_BUFFER_PORT == drop_param.type && (CTC_INGRESS == drop_param.dir || (CTC_EGRESS == drop_param.dir && drop_param.non_uc)))
        {
            ctc_cli_out("----------------\n");
            return CLI_SUCCESS;
        }

        /*2. get wred drop param*/
        tempdrop_param.drop.mode = CTC_QUEUE_DROP_WRED;
        if(g_ctcs_api_en)
        {
            ret = ctcs_qos_get_drop_scheme(g_api_ldev, &tempdrop_param);
        }
        else
        {
            ret = ctc_qos_get_drop_scheme(&tempdrop_param);
        }
        if (ret < 0)
        {
            if(CTC_E_INVALID_CONFIG == ret)
            {
                non_ecn = 1;
            }
            
            tempdrop_param.drop.mode = CTC_QUEUE_DROP_WRED_NON_ECN;
            if(g_ctcs_api_en)
            {
                ret = ctcs_qos_get_drop_scheme(g_api_ldev, &tempdrop_param);
            }
            else
            {
                ret = ctc_qos_get_drop_scheme(&tempdrop_param);
            }
        }

        if(ret == 0)
        {
            _ctc_cli_queue_drop_wred_show(vty, tempdrop_param, non_ecn);
        }
        else if (CTC_E_NOT_SUPPORT != ret && CTC_E_INVALID_PARAM != ret && CTC_E_INVALID_CONFIG != ret)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

    }
    ctc_cli_out("----------------\n");
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_resrc_ingress,
        ctc_cli_qos_set_resrc_ingress_cmd,
        "qos resrc-mgr ingress (classify port GPHYPORT_ID priority PRIORITY pool POOL|port-min port GPHYPORT_ID (priority-class PRI|sc SC_ID|) threshold THRD) (non-uc|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Ingress",
        "Classify",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Sc Pool",
        "Sc Pool value <0-3>",
        "Port minimum guarantee",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Prio class",
        "Prio class value",
        "Sc pool",
        "Sc pool value",
        "Guarantee threshold",
        "Guarantee threshold value",
        "Non-uc traffic")
{
    uint8  index = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));

    index = CTC_CLI_GET_ARGC_INDEX("classify");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32_RANGE("port", resrc.u.port_min.gport, argv[index + 2], 0, CTC_MAX_UINT32_VALUE);
        CTC_CLI_GET_UINT8_RANGE("priority", resrc.u.pool.priority, argv[index + 4], 0, CTC_MAX_UINT8_VALUE);
        CTC_CLI_GET_UINT8_RANGE("pool", resrc.u.pool.pool, argv[index + 6], 0, CTC_MAX_UINT8_VALUE);
        resrc.u.pool.dir = CTC_INGRESS;
        resrc.cfg_type = CTC_QOS_RESRC_CFG_POOL_CLASSIFY;

        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            resrc.u.pool.non_uc = 1;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("port-min");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32_RANGE("port", resrc.u.port_min.gport, argv[index + 2], 0, CTC_MAX_UINT32_VALUE);

        index = CTC_CLI_GET_ARGC_INDEX("priority-class");
        if (0xFF != index)
        {
            resrc.u.port_min.prio_class_en = 1;
            CTC_CLI_GET_UINT8_RANGE("priority class", resrc.u.port_min.prio_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        }

        index = CTC_CLI_GET_ARGC_INDEX("sc");
        if (0xFF != index)
        {
            resrc.u.port_min.prio_class_en = 2;
            CTC_CLI_GET_UINT8_RANGE("sc pool", resrc.u.port_min.prio_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        }

        index = CTC_CLI_GET_ARGC_INDEX("threshold");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT16_RANGE("threshold", resrc.u.port_min.threshold, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        }
        resrc.u.port_min.dir = CTC_INGRESS;
        resrc.cfg_type = CTC_QOS_RESRC_CFG_PORT_MIN;
        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            resrc.u.port_min.non_uc = 1;
        }
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_set_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_resrc_egress,
        ctc_cli_qos_set_resrc_egress_cmd,
        "qos resrc-mgr egress (classify (port GPHYPORT_ID priority PRIORITY |queue "CTC_CLI_QOS_QUEUE_ID_STR") pool POOL|port-min port GPHYPORT_ID (priority-class PRI|sc SC_ID|) threshold THRD) (non-uc|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Egress",
        "Classify",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Queue",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Pool",
        "Pool value <0-3>",
        "Port minimum guarantee",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Prio class",
        "Prio class value",
        "Sc pool",
        "Sc pool value",
        "Threshold",
        "Threshold value",
        "Non-uc traffic")
{
    uint8  index = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));

    index = CTC_CLI_GET_ARGC_INDEX("classify");
    if (0xFF != index)
    {
        index = CTC_CLI_GET_ARGC_INDEX("queue");
        if (0xFF != index)
        {
            _ctc_cli_qos_queue_id_parser(vty, &resrc.u.pool.queue, &argv[0], argc);
        }
        else 
        {
            index = CTC_CLI_GET_ARGC_INDEX("port");
            if (0xFF != index)
            {
                CTC_CLI_GET_UINT32_RANGE("port", resrc.u.pool.gport, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
                CTC_CLI_GET_UINT8_RANGE("priority", resrc.u.pool.priority, argv[index + 3], 0, CTC_MAX_UINT8_VALUE);
            }
        }

        index = CTC_CLI_GET_ARGC_INDEX("pool");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT8_RANGE("pool", resrc.u.pool.pool, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        }
        resrc.u.pool.dir = CTC_EGRESS;
        resrc.cfg_type = CTC_QOS_RESRC_CFG_POOL_CLASSIFY;

        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            resrc.u.pool.non_uc = 1;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("port-min");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32_RANGE("port", resrc.u.port_min.gport, argv[index + 2], 0, CTC_MAX_UINT32_VALUE);

        index = CTC_CLI_GET_ARGC_INDEX("priority-class");
        if (0xFF != index)
        {
            resrc.u.port_min.prio_class_en = 1;
            CTC_CLI_GET_UINT8_RANGE("priority class", resrc.u.port_min.prio_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        }
        index = CTC_CLI_GET_ARGC_INDEX("sc");
        if (0xFF != index)
        {
            resrc.u.port_min.prio_class_en = 2;
            CTC_CLI_GET_UINT8_RANGE("sc pool", resrc.u.port_min.prio_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        }
        index = CTC_CLI_GET_ARGC_INDEX("threshold");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT16_RANGE("threshold", resrc.u.port_min.threshold, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        }
        resrc.u.port_min.dir = CTC_EGRESS;
        resrc.cfg_type = CTC_QOS_RESRC_CFG_PORT_MIN;

        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            resrc.u.port_min.non_uc = 1;
        }
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_set_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}
CTC_CLI(ctc_cli_qos_get_resrc,
        ctc_cli_qos_get_resrc_cmd,
        "show qos resrc-mgr (ingress|egress) (classify (port GPHYPORT_ID priority PRIORITY | queue "CTC_CLI_QOS_QUEUE_ID_STR") pool|port-min port GPHYPORT_ID (priority-class PRI|sc SC_ID|) threshold) (non-uc|)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Ingress",
        "Egress",
        "Classify",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Queue",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Pool",
        "Port minimum guarantee",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Prio class",
        "Prio class value",
        "Sc pool",
        "Sc pool value",
        "Threshold",
        "Non-uc traffic")
{
    uint8  index = 0;
    uint8  dir = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));
    index = CTC_CLI_GET_ARGC_INDEX("ingress");
    if (0xFF != index)
    {
        dir = CTC_INGRESS;
    }
    else
    {
        dir = CTC_EGRESS;
    }

    index = CTC_CLI_GET_ARGC_INDEX("classify");
    if (0xFF != index)
    {
        index = CTC_CLI_GET_ARGC_INDEX("queue");
        if (0xFF != index)
        {
            _ctc_cli_qos_queue_id_parser(vty, &resrc.u.pool.queue, &argv[0], argc);
        }
        else 
        {
            index = CTC_CLI_GET_ARGC_INDEX("port");
            if (0xFF != index)
            {
                CTC_CLI_GET_UINT32_RANGE("port", resrc.u.pool.gport, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
                CTC_CLI_GET_UINT8_RANGE("priority", resrc.u.pool.priority, argv[index + 3], 0, CTC_MAX_UINT8_VALUE);
            }
        }
        resrc.cfg_type = CTC_QOS_RESRC_CFG_POOL_CLASSIFY;
        resrc.u.pool.dir = dir;

        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            resrc.u.pool.non_uc = 1;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("port-min");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32_RANGE("port", resrc.u.port_min.gport, argv[index + 2], 0, CTC_MAX_UINT32_VALUE);
        index = CTC_CLI_GET_ARGC_INDEX("priority-class");
        if (0xFF != index)
        {
            resrc.u.port_min.prio_class_en = 1;
            CTC_CLI_GET_UINT8_RANGE("priority class", resrc.u.port_min.prio_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        }
        index = CTC_CLI_GET_ARGC_INDEX("sc");
        if (0xFF != index)
        {
            resrc.u.port_min.prio_class_en = 2;
            CTC_CLI_GET_UINT8_RANGE("sc pool", resrc.u.port_min.prio_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        }
        resrc.u.port_min.dir = dir;
        resrc.cfg_type = CTC_QOS_RESRC_CFG_PORT_MIN;
        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            resrc.u.port_min.non_uc = 1;
        }
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_get_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if(resrc.cfg_type == CTC_QOS_RESRC_CFG_POOL_CLASSIFY)
    {
        ctc_cli_out("%-10s\n", "Pool information");
        ctc_cli_out("----------------\n");
        ctc_cli_out("%-19s : %-8u\n",
                        "Pool type", resrc.u.pool.pool);
    }
    else if(resrc.cfg_type == CTC_QOS_RESRC_CFG_PORT_MIN)
    {
        ctc_cli_out("%-10s\n", "Port-min information");
        ctc_cli_out("----------------\n");
        if(resrc.u.port_min.prio_class_en == 1)
        {
        ctc_cli_out("%-19s : %-8u\n",
                        "Priority class", resrc.u.port_min.prio_class);
        }
        else if (resrc.u.port_min.prio_class_en == 2)
        {
            ctc_cli_out("%-19s : %-8u\n",
                        "Sc pool", resrc.u.port_min.prio_class);
        }
        ctc_cli_out("%-19s : %-8u\n",
                        "Threshold", resrc.u.port_min.threshold);
    }
    ctc_cli_out("----------------\n");

    return CLI_SUCCESS;
}
CTC_CLI(ctc_cli_qos_set_resrc_queue_drop,
        ctc_cli_qos_set_resrc_queue_drop_cmd,
        "qos resrc-mgr queue-drop level-profile",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Queue drop with congest level",
        "Use level profile")
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    CTC_CLI_QOS_DROP_ARRAY_INIT;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_QUEUE_DROP;
    sal_memcpy(&resrc.u.queue_drop, g_qos_drop_array, sizeof(ctc_qos_drop_array));

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_set_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_resrc_flow_ctl,
        ctc_cli_qos_set_resrc_flow_ctl_cmd,
        "qos resrc-mgr flow-ctl (port GPHYPORT_ID) (priority-class PRI|) (xon-thrd TRHD xoff-thrd THRD drop-thrd THRD) (out-of-band|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Flow control",
        CTC_CLI_PORT_M_STR,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Cos used for PFC",
        "<0-7>",
        "Xon thresthold",
        "Threshold",
        "Xoff thresthold",
        "Threshold",
        "Drop thresthold",
        "Threshold",
        "Out of band flow control")
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;
    uint8 index =0;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_FLOW_CTL;

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("port", resrc.u.flow_ctl.gport, argv[index + 1]);
    }
#ifdef EFC_BK
    index = CTC_CLI_GET_ARGC_INDEX("efc");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.type = CTC_QOS_FC_TYPE_EFC;
    }
    index = CTC_CLI_GET_ARGC_INDEX("replication-efc");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.type = CTC_QOS_FC_TYPE_EFC_REPLICATION;
    }
    index = CTC_CLI_GET_ARGC_INDEX("efc-type");
    if (0xFF != index)
    {
        if (resrc.u.flow_ctl.type != CTC_QOS_FC_TYPE_EFC_REPLICATION)
        {
            resrc.u.flow_ctl.type = CTC_QOS_FC_TYPE_EFC;
        }

        if (CLI_CLI_STR_EQUAL("low", index + 1))
        {
            resrc.u.flow_ctl.efc_type = CTC_QOS_EFC_TYPE_LOW;
        }
        else if (CLI_CLI_STR_EQUAL("mid", index + 1))
        {
            resrc.u.flow_ctl.efc_type = CTC_QOS_EFC_TYPE_MID;
        }
        else if (CLI_CLI_STR_EQUAL("high", index + 1))
        {
            resrc.u.flow_ctl.efc_type = CTC_QOS_EFC_TYPE_HIGH;
        }
    }
#endif

    index = CTC_CLI_GET_ARGC_INDEX("priority-class");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.is_pfc = 1;
        CTC_CLI_GET_UINT16("priority class", resrc.u.flow_ctl.priority_class, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("xon-thrd");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("xon-thrd", resrc.u.flow_ctl.xon_thrd, argv[index + 1]);
    }


    index = CTC_CLI_GET_ARGC_INDEX("xoff-thrd");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("xoff-thrd", resrc.u.flow_ctl.xoff_thrd, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("drop-thrd");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("drop-thrd", resrc.u.flow_ctl.drop_thrd, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("out-of-band");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.is_oobfc = 1;
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_set_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_get_resrc_flow_ctl,
        ctc_cli_qos_get_resrc_flow_ctl_cmd,
        "show qos resrc-mgr flow-ctl (port GPHYPORT_ID) (priority-class PRI|) (out-of-band|)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Flow control",
        CTC_CLI_PORT_M_STR,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Cos used for PFC",
        "<0-7>",
        "out of band flow control")
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;
    uint8 index =0;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_FLOW_CTL;

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("port", resrc.u.flow_ctl.gport, argv[index + 1]);
    }
#ifdef EFC_BK
    index = CTC_CLI_GET_ARGC_INDEX("efc");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.type = CTC_QOS_FC_TYPE_EFC;
    }
    index = CTC_CLI_GET_ARGC_INDEX("replication-efc");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.type = CTC_QOS_FC_TYPE_EFC_REPLICATION;
    }
    index = CTC_CLI_GET_ARGC_INDEX("efc-type");
    if (0xFF != index)
    {
        if (resrc.u.flow_ctl.type != CTC_QOS_FC_TYPE_EFC_REPLICATION)
        {
            resrc.u.flow_ctl.type = CTC_QOS_FC_TYPE_EFC;
        }

        if (CLI_CLI_STR_EQUAL("low", index + 1))
        {
            resrc.u.flow_ctl.efc_type = CTC_QOS_EFC_TYPE_LOW;
        }
        else if (CLI_CLI_STR_EQUAL("mid", index + 1))
        {
            resrc.u.flow_ctl.efc_type = CTC_QOS_EFC_TYPE_MID;
        }
        else if (CLI_CLI_STR_EQUAL("high", index + 1))
        {
            resrc.u.flow_ctl.efc_type = CTC_QOS_EFC_TYPE_HIGH;
        }
    }
#endif 

    index = CTC_CLI_GET_ARGC_INDEX("priority-class");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.is_pfc = 1;
        CTC_CLI_GET_UINT16("priority class", resrc.u.flow_ctl.priority_class, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("out-of-band");
    if (0xFF != index)
    {
        resrc.u.flow_ctl.is_oobfc = 1;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_get_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("%-10s\n", "Flow-control information");
    ctc_cli_out("----------------\n");
    ctc_cli_out("%-19s : %-8u\n","Xon threshold", resrc.u.flow_ctl.xon_thrd);
    ctc_cli_out("%-19s : %-8u\n","Xoff threshold", resrc.u.flow_ctl.xoff_thrd);
    ctc_cli_out("%-19s : %-8u\n","Drop threshold", resrc.u.flow_ctl.drop_thrd);
    ctc_cli_out("----------------\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_show_resrc_usage,
        ctc_cli_qos_show_resrc_usage_cmd,
        "show qos resrc-mgr (pool-count|queue-count" CTC_CLI_QOS_QUEUE_ID_STR "|port-count port GPHYPORT_ID|priority-class-count port GPHYPORT_ID priority-class PRI|(igs-portsc-count|egs-portsc-count) port GPHYPORT_ID sc SC_ID) (non-uc|)("CTC_CLI_PP_ID_STR"|)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Pool count",
        "Queue count",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Port count",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Port priority class count",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Cos used for PFC",
        "<0-7>",
        "Ingress Port sc count",
        "Egress Port sc count",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Sc pool",
        "Sc pool value",
        "Non-uc traffic",
        CTC_CLI_PP_ID_DESC)
{
    int32 ret = CLI_SUCCESS;
    uint8  index = 0;
    uint8  pool = 0;
    ctc_qos_resrc_pool_stats_t stats;

    sal_memset(&stats, 0, sizeof(stats));
    index = CTC_CLI_GET_ARGC_INDEX("pp-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("pp", stats.pp_id, argv[index + 1]);
    }

    CTC_CLI_PP_ID_SET(index, stats.pp_id);

    index = CTC_CLI_GET_ARGC_INDEX("pool-count");
    if (0xFF != index)
    {
        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            stats.non_uc = 1;
        }

        ctc_cli_out("%-10s\n", "Ingress pool");
        ctc_cli_out("----------------\n");
        for (pool = 0; pool < 4; pool ++)
        {
            stats.type = CTC_QOS_RESRC_STATS_IGS_POOL_COUNT;
            stats.pool = pool;
            stats.count = 0;

            if (g_ctcs_api_en)
            {
                ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
            }
            else
            {
                ret = ctc_qos_query_pool_stats(&stats);
            }
            if (ret < 0 && pool < 3)
            {
                ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
                return CLI_ERROR;
            }

            ctc_cli_out("%-5s%u: %u\n", "Pool", pool, stats.count);
        }
        stats.type = CTC_QOS_RESRC_STATS_IGS_POOL_COUNT;
        stats.pool = CTC_QOS_IGS_RESRC_ROUND_TRIP_POOL;
        stats.count = 0;

        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }

        ctc_cli_out("%-5s : %u\n", "RT", stats.count);
        stats.type = CTC_QOS_RESRC_STATS_IGS_TOTAL_COUNT;
        stats.count = 0;
        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-5s : %u\n", "Total", stats.count);
        ctc_cli_out("\n");
        ctc_cli_out("%-5s\n", "Egress pool");
        ctc_cli_out("----------------\n");
        for (pool = 0; pool < 4; pool ++)
        {
            stats.type = CTC_QOS_RESRC_STATS_EGS_POOL_COUNT;
            stats.pool = pool;
            stats.count = 0;
            if (g_ctcs_api_en)
            {
                ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
            }
            else
            {
                ret = ctc_qos_query_pool_stats(&stats);
            }
            if (ret < 0)
            {
                ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
                return CLI_ERROR;
            }
            ctc_cli_out("%-5s%u: %u\n", "Pool", pool, stats.count);
        }

        stats.type = CTC_QOS_RESRC_STATS_EGS_TOTAL_COUNT;
        stats.count = 0;
        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-5s : %u\n", "Total", stats.count);
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-count");
    if (0xFF != index)
    {
        _ctc_cli_qos_queue_id_parser(vty, &stats.queue, &argv[0], argc);

        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            stats.non_uc = 1;
        }
        stats.type = CTC_QOS_RESRC_STATS_QUEUE_COUNT;

        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-15s   :  %u\n", "queue-count", stats.count);
    }

    index = CTC_CLI_GET_ARGC_INDEX("port-count");
    if (0xFF != index)
    {
        ctc_cli_out("%-10s\n", "Ingress port");
        ctc_cli_out("----------------\n");
        CTC_CLI_GET_UINT32("gport", stats.gport, argv[index + 2]);
        index = CTC_CLI_GET_ARGC_INDEX("non-uc");
        if (0xFF != index)
        {
            stats.non_uc = 1;
        }
        stats.type = CTC_QOS_RESRC_STATS_IGS_PORT_COUNT;
        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-5s : %u\n", "Port", stats.count);
        ctc_cli_out("\n");
        ctc_cli_out("%-10s\n", "Engress port");
        ctc_cli_out("----------------\n");
        stats.type = CTC_QOS_RESRC_STATS_EGS_PORT_COUNT;
        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-5s : %u\n", "Port", stats.count);
    }

    index = CTC_CLI_GET_ARGC_INDEX("priority-class-count");
    if (0xFF != index)
    {
        stats.type = CTC_QOS_RESRC_STATS_PRI_CLASS_COUNT;

        CTC_CLI_GET_UINT32("gport", stats.gport, argv[index + 2]);
        CTC_CLI_GET_UINT32("pri_class", stats.pri_class, argv[index + 4]);
        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-15s   :  %u\n", "priority-class-count", stats.count);
    }
    index = CTC_CLI_GET_ARGC_INDEX("igs-portsc-count");
    if (0xFF != index)
    {
        stats.type = CTC_QOS_RESRC_STATS_IGS_PORT_SC_COUNT;

        CTC_CLI_GET_UINT32("gport", stats.gport, argv[index + 2]);
        CTC_CLI_GET_UINT32("sc_pool", stats.pool, argv[index + 4]);
        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-15s   :  %u\n", "igs-portsc-count", stats.count);
    }
    index = CTC_CLI_GET_ARGC_INDEX("egs-portsc-count");
    if (0xFF != index)
    {
        stats.type = CTC_QOS_RESRC_STATS_EGS_PORT_SC_COUNT;

        CTC_CLI_GET_UINT32("gport", stats.gport, argv[index + 2]);
        CTC_CLI_GET_UINT32("sc_pool", stats.pool, argv[index + 4]);
        if(g_ctcs_api_en)
        {
             ret = ctcs_qos_query_pool_stats(g_api_ldev, &stats);
        }
        else
        {
            ret = ctc_qos_query_pool_stats(&stats);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-15s   :  %u\n", "egs-portsc-count", stats.count);
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_resrc_fcdl,
        ctc_cli_qos_set_resrc_fcdl_cmd,
        "qos resrc-mgr fcdl detect (interval VALUE \
        | (port GPHYPORT_ID (priority-class PRI PRI| ) mult MULT (enable (mode MODE (timeout TIME|) |) |disable)) \
        | action (transmit | drop))",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Flow control dead-lock",
        "Detect",
        "Detect Interval",
        "Value",
        CTC_CLI_PORT_M_STR,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Cos used for PFC",
        "<0-7>",
        "<0-7>",
        "Detect multiplier",
        "Value",
        "Enable",
        "Recover deadlock mode",
        "0:detect only, 1:detect & disable flowctl, 2:detect & disable flowctl & enable flowctl again when time expired",
        "Enable flowctl after timer expired, only valid when mode is 2",
        "Value, uint:ms",
        "Disable",
        "Detect action",
        "Fowarding packet",
        "Drop incoming packet")
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;
    uint8 flag = 0;

    sal_memset(&resrc, 0, sizeof(resrc));
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_FCDL_DETECT;
    resrc.u.fcdl_detect.valid_num = 2;

    index = CTC_CLI_GET_ARGC_INDEX("interval");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_FCDL_INTERVAL;
        CTC_CLI_GET_UINT32("interval", glb_cfg.u.value, argv[index + 1]);
        flag = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("action");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_FCDL_ACTION;

        index = CTC_CLI_GET_ARGC_INDEX("transmit");
        if (0xFF != index)
        {
            glb_cfg.u.value = CTC_QOS_FCDL_ACTION_TRANSIMIT;
        }
        index = CTC_CLI_GET_ARGC_INDEX("drop");
        if (0xFF != index)
        {
            glb_cfg.u.value = CTC_QOS_FCDL_ACTION_DROP;
        }
        flag = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("port", resrc.u.fcdl_detect.gport, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("priority-class");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("priority class", resrc.u.fcdl_detect.priority_class[0], argv[index + 1]);
        CTC_CLI_GET_UINT8("priority class", resrc.u.fcdl_detect.priority_class[1], argv[index + 2]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("mult");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("mult", resrc.u.fcdl_detect.detect_mult, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        resrc.u.fcdl_detect.enable = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("mode");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("mode", resrc.u.fcdl_detect.mode, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("timeout");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("timeout", resrc.u.fcdl_detect.timeout, argv[index + 1]);
    }
    if(flag == 0)
    {
        if(g_ctcs_api_en)
        {
            ret = ctcs_qos_set_resrc(g_api_ldev, &resrc);
        }
        else
        {
            ret = ctc_qos_set_resrc(&resrc);
        }
        
    }
    else
    {
        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
        }
        else
        {
            ret = ctc_qos_set_global_config(&glb_cfg);
        }
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_show_resrc_fcdl,
        ctc_cli_qos_show_resrc_fcdl_cmd,
        "show qos resrc-mgr fcdl detect (interval | (port GPHYPORT_ID (priority-class PRI|)) | action)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Flow control dead-lock",
        "Detect",
        "Detect Interval",
        CTC_CLI_PORT_M_STR,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Cos used for PFC",
        "<0-7>",
        "Detect action")
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;
    uint8 flag = 0;

    sal_memset(&resrc, 0, sizeof(resrc));
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_FCDL_DETECT;

    index = CTC_CLI_GET_ARGC_INDEX("interval");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_FCDL_INTERVAL;
        flag = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("action");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_FCDL_ACTION;
        flag = 1;
    }
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("port", resrc.u.fcdl_detect.gport, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("priority-class");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("priority class", resrc.u.fcdl_detect.priority_class[0], argv[index + 1]);
    }

    if(flag == 0)
    {
        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_get_resrc(g_api_ldev, &resrc);
        }
        else
        {
            ret = ctc_qos_get_resrc(&resrc);
        }

        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-10s\n", "Flow-control deadlock detect information");
        ctc_cli_out("------------------------\n");
        ctc_cli_out("%-19s : %-8u\n", "enable", resrc.u.fcdl_detect.enable);
        ctc_cli_out("%-19s : %-8u\n", "valid num", resrc.u.fcdl_detect.valid_num);
        ctc_cli_out("%-19s : %-8u\n", "detect_mult", resrc.u.fcdl_detect.detect_mult);
        ctc_cli_out("%-19s : %-8u\n", "mode", resrc.u.fcdl_detect.mode);
        ctc_cli_out("%-19s : %-8u\n", "timeout", resrc.u.fcdl_detect.timeout);
        ctc_cli_out("------------------------\n");
    }
    else
    {
        if (g_ctcs_api_en)
        {
            ret = ctcs_qos_get_global_config(g_api_ldev, &glb_cfg);
        }
        else
        {
            ret = ctc_qos_get_global_config(&glb_cfg);
        }

        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        if (glb_cfg.cfg_type == CTC_QOS_GLB_CFG_FCDL_ACTION)
        {
            ctc_cli_out("%-19s : %-8s\n", "action", glb_cfg.u.value ? "drop" : "transmit");
        }
        else if (glb_cfg.cfg_type == CTC_QOS_GLB_CFG_FCDL_INTERVAL)
        {
            ctc_cli_out("%-19s : %-8u\n", "interval", glb_cfg.u.value );
        }

    }
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_queue_min,
        ctc_cli_qos_set_queue_min_cmd,
        "qos resrc-mgr queue-min" CTC_CLI_QOS_QUEUE_ID_STR "(threshold THRD))",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Queue minimum guarantee",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Threshold",
        "Threshold value")
{
    uint8  index = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_QUEUE_MIN;

    _ctc_cli_qos_queue_id_parser(vty, &resrc.u.queue_min.queue, &argv[0], argc);

    index = CTC_CLI_GET_ARGC_INDEX("threshold");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("threshold", resrc.u.queue_min.threshold, argv[index + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_set_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_get_queue_min,
        ctc_cli_qos_get_queue_min_cmd,
        "show qos resrc-mgr queue-min" CTC_CLI_QOS_QUEUE_ID_STR,
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Queue minimum guarantee",
        CTC_CLI_QOS_QUEUE_ID_DSCP)
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_QUEUE_MIN;

    _ctc_cli_qos_queue_id_parser(vty, &resrc.u.queue_min.queue, &argv[0], argc);
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_get_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("%-10s\n", "Queue-min Thrd information");
    ctc_cli_out("------------------------\n");
    ctc_cli_out("%-19s : %-8u\n","Threshold:", resrc.u.queue_min.threshold);
    ctc_cli_out("------------------------\n");
    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_set_obm_pool,
        ctc_cli_qos_set_obm_pool_cmd,
        "qos resrc-mgr obm-pool POOL_INDEX lossy0 LOSSY0_THRD lossy1 LOSSY1_THRD lossless0 LOSSLESS0_THRD lossless1 LOSSLESS1_THRD (xon XON_THRD xoff XOFF_THRD|)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "OBM pool threshold",
        "OBM pool index",
        "Lossy0 Threshold",
        "Lossy0 Threshold value",
        "Lossy1 Threshold",
        "Lossy1 Threshold value",
        "Lossless0 Threshold",
        "Lossless0 Threshold value",
        "Lossless1 Threshold",
        "Lossless1 Threshold value",
        "Xon Threshold",
        "Xon Threshold value",
        "Xoff Threshold",
        "Xoff Threshold value")
{
    uint8  index = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_OBM_POOL;
    CTC_CLI_GET_UINT8("pool-index", resrc.u.obm_pool.index, argv[0]);
    CTC_CLI_GET_UINT16("lossy0", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSY0], argv[1]);
    CTC_CLI_GET_UINT16("lossy1", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSY1], argv[2]);
    CTC_CLI_GET_UINT16("lossless0", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSLESS0], argv[3]);
    CTC_CLI_GET_UINT16("lossless1", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSLESS1], argv[4]);

    index = CTC_CLI_GET_ARGC_INDEX("xon");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("xon", resrc.u.obm_pool.xon_thrd, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("xoff");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("xoff", resrc.u.obm_pool.xoff_thrd, argv[index + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_set_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_get_obm_pool,
        ctc_cli_qos_get_obm_pool_cmd,
        "show qos resrc-mgr obm-pool POOL_INDEX",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "OBM pool threshold",
        "OBM pool index")
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_OBM_POOL;
    CTC_CLI_GET_UINT8("pool-index", resrc.u.obm_pool.index, argv[0]);

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_resrc(g_api_ldev, &resrc);
    }
    else
    {
        ret = ctc_qos_get_resrc(&resrc);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("OBM pool %d Thrd information\n", resrc.u.obm_pool.index);
    ctc_cli_out("------------------------\n");
    ctc_cli_out("%-19s : %-8u\n","Xon Thrd:", resrc.u.obm_pool.xon_thrd);
    ctc_cli_out("%-19s : %-8u\n","Xoff Thrd:", resrc.u.obm_pool.xoff_thrd);
    ctc_cli_out("%-19s : %-8u\n","Lossy0 Thrd:", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSY0]);
    ctc_cli_out("%-19s : %-8u\n","Lossy1 Thrd:", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSY1]);
    ctc_cli_out("%-19s : %-8u\n","Lossyless0 Thrd:", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSLESS0]);
    ctc_cli_out("%-19s : %-8u\n","Lossyless1 Thrd:", resrc.u.obm_pool.pool_thrd[CTC_QOS_OBM_RESRC_POOL_LOSSLESS1]);
    ctc_cli_out("------------------------\n");
    return CLI_SUCCESS;
}

#define stats_cli ""

CTC_CLI(ctc_cli_qos_show_port_queue_stats,
        ctc_cli_qos_show_port_queue_stats_cmd,
        "show qos stats ((service-id SERVICE port GPHYPORT_ID ) | (port GPHYPORT_ID (end-port GPHYPORT_ID|) | all-port) \
        | (reason-id REASON (end-reason-id REASON|) | all-reason)) (queue-id QUEUE_ID|) (class-prio CLASS_PRIO|)(all|drop-pkt|deq-pkt|)("CTC_CLI_PP_BMP"|)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_STATS_STR,
        "Service id",
        CTC_CLI_QOS_SERVICE_VAL,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "End port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "All port",
        "Cpu reason",
        "Cpu reason id",
        "End cpu reason",
        "End cpu reason id",
        "All reason",
        CTC_CLI_QOS_QUEUE_STR,
        CTC_CLI_QOS_QUEUE_VAL,
        "Class prioity",
        "Class prioity value",
        "ALL packet",
        "Dropped packet",
        "Deq packet",
        CTC_CLI_PP_BMP_DESC)
{
    int32  ret = CLI_SUCCESS;
    ctc_qos_queue_stats_t stats_param;
    uint8 index = 0;
    uint16 start = 0;
    uint16 end = CTC_QUEUE_NUM_PER_REASON;
    uint16 qid = 0;
    uint32 capability[CTC_GLOBAL_CAPABILITY_MAX] = {0};
    uint32 max_port_num_per_chip = 0;
    uint32 gport_start = 0;
    uint32 gport_end = 0;
    uint16 lport_start = 0;
    uint16 lport_end = 0;
    uint16 loop = 0;
    uint8  loop_flag = 0;
    uint8 gchip = 0;
    uint16 reason_start = 0;
    uint16 reason_end = 0;
    uint8  cli_flag = 0;
    uint8  gport_flag = 0;
    uint8  is_all = 0;
    uint8 mchan_index = 0;

    sal_memset(&stats_param, 0, sizeof(ctc_qos_queue_stats_t));

    if(g_ctcs_api_en)
    {
        ret = ctcs_global_ctl_get(g_api_ldev, CTC_GLOBAL_CHIP_CAPABILITY, capability);
    }
    else
    {
        ret = ctc_global_ctl_get(CTC_GLOBAL_CHIP_CAPABILITY, capability);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    max_port_num_per_chip = capability[CTC_GLOBAL_CAPABILITY_MAX_PORT_NUM];

    _ctc_cli_qos_queue_id_parser(vty, &stats_param.queue, &argv[0], argc);


    index = CTC_CLI_GET_ARGC_INDEX("all-port");
    if (0xFF != index)
    {
        stats_param.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;
        lport_start = 0;
        lport_end = max_port_num_per_chip - 1;
        if(g_ctcs_api_en)
        {
            ret = ctcs_get_gchip_id(g_api_ldev, &gchip);
        }
        else
        {
            ret = ctc_get_gchip_id(g_api_ldev, &gchip);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        is_all = 1;
    }
    else
    {
        index = CTC_CLI_GET_ARGC_INDEX("port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32_RANGE("gport_start", gport_start, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
            mchan_index = CTC_MAP_GPORT_TO_MCHAN_IDX(gport_start);
            gport_end = gport_start;
        }
        index = CTC_CLI_GET_ARGC_INDEX("end-port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32_RANGE("gport_end", gport_end, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        }
        if ((CTC_MAP_GPORT_TO_GCHIP(gport_start) != CTC_MAP_GPORT_TO_GCHIP(gport_end)) || (gport_start > gport_end) || mchan_index != CTC_MAP_GPORT_TO_MCHAN_IDX(gport_end))
        {
            ctc_cli_out("%% GPort range error !\n");
            return CLI_ERROR;
        }
        lport_start = CTC_MAP_GPORT_TO_LPORT(gport_start);
        lport_end = CTC_MAP_GPORT_TO_LPORT(gport_end);
        gchip = CTC_MAP_GPORT_TO_GCHIP(gport_start);
    }

    index = CTC_CLI_GET_ARGC_INDEX("all-reason");
    if (0xFF != index)
    {
        stats_param.queue.queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
        reason_start = 0;
        reason_end = CTC_PKT_CPU_REASON_MAX_COUNT - 1;
        is_all = 1;
    }
    else
    {
        index = CTC_CLI_GET_ARGC_INDEX("reason-id");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT16_RANGE("reason id", reason_start, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
            reason_end = reason_start;
        }
        index = CTC_CLI_GET_ARGC_INDEX("end-reason-id");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT16_RANGE("end reason id", reason_end, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        }
        if (reason_end < reason_start)
        {
            ctc_cli_out("%% Reason id range error !\n");
            return CLI_ERROR;
        }
        if (reason_end >= CTC_PKT_CPU_REASON_MAX_COUNT)
        {
            reason_end = CTC_PKT_CPU_REASON_MAX_COUNT - 1;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index )
    {
        start = stats_param.queue.queue_id;
        end = start + 1;
    }

    CTC_CLI_GET_PP_BMP(index, stats_param.pp_bmp);

    index = CTC_CLI_GET_ARGC_INDEX("all");
    if (0xFF != index)
    {
       stats_param.stats_en = 3;
    }

    index = CTC_CLI_GET_ARGC_INDEX("drop-pkt");
    if (0xFF != index)
    {
       stats_param.stats_en = 2;
    }

    index = CTC_CLI_GET_ARGC_INDEX("deq-pkt");
    if (0xFF != index)
    {
       stats_param.stats_en = 1;
    }

    loop_flag = (stats_param.queue.queue_type == CTC_QUEUE_TYPE_EXCP_CPU);

    ctc_cli_out("%-10s %-10s %-15s %-15s %-15s %-15s\n", loop_flag ? "Reason" : "Gport","Queue id", "Deq(Pkts)", "Deq(Bytes)", "Drop(Pkts)", "Drop(Bytes)");
    ctc_cli_out("--------------------------------------------------------------------------------\n");


    for(loop = (loop_flag ? reason_start : lport_start); loop <= (loop_flag ? reason_end : lport_end); loop++)
    {
        cli_flag = 0;
        gport_flag = 1;
        if (loop_flag)
        {
            stats_param.queue.cpu_reason = loop;
        }
        else
        {
            stats_param.queue.gport = mchan_index ? CTC_MAP_LPORT_TO_GPORT_MCHAN(gchip, loop, mchan_index) : CTC_MAP_LPORT_TO_GPORT(gchip, loop);
        }
        for (qid = start ; qid < end ; qid++)
        {
            stats_param.queue.queue_id = qid;
            sal_memset(&stats_param.stats, 0, sizeof(ctc_qos_queue_stats_info_t));
            if (g_ctcs_api_en)
            {
                ret = ctcs_qos_query_queue_stats(g_api_ldev, &stats_param);
            }
            else
            {
                ret = ctc_qos_query_queue_stats(&stats_param);
            }
            if (ret < 0)
            {
                break;
            }

            if (is_all
                && (stats_param.stats.deq_packets == 0)
                && (stats_param.stats.drop_packets == 0))
            {
                continue;
            }
            if (loop_flag)
            {
                ctc_cli_out("%-10d ", stats_param.queue.cpu_reason);
            }
            else if (gport_flag)
            {
                ctc_cli_out("0x%-8x ", stats_param.queue.gport);
                gport_flag = 0;
            }
            else
            {
                ctc_cli_out("%-10s ", " ");
            }
            if ((stats_param.stats.deq_packets != 0 && stats_param.stats.deq_bytes == 0) || 
                (stats_param.stats.drop_packets != 0 && stats_param.stats.drop_bytes == 0))
            {
                ctc_cli_out("%-10d %-15"PRIu64" %-15s %-15"PRIu64" %-15s\n",
                            stats_param.queue.queue_id,
                            stats_param.stats.deq_packets, "-",
                            stats_param.stats.drop_packets, "-");
            } 
            else
            {
                ctc_cli_out("%-10d %-15"PRIu64" %-15"PRIu64" %-15"PRIu64" %-15"PRIu64"\n",
                            stats_param.queue.queue_id,
                            stats_param.stats.deq_packets, stats_param.stats.deq_bytes,
                            stats_param.stats.drop_packets, stats_param.stats.drop_bytes);
            }
            cli_flag = 1;
        }
        if (cli_flag)
        {
            ctc_cli_out("--------------------------------------------------------------------------------\n");
        }
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_clear_port_queue_stats,
        ctc_cli_qos_clear_port_queue_stats_cmd,
        "clear qos stats ((service-id SERVICE port GPHYPORT_ID ) | (port GPHYPORT_ID (end-port GPHYPORT_ID|) | all-port) \
        | (reason-id REASON (end-reason-id REASON|) | all-reason)) (queue-id QUEUE_ID|) (class-prio CLASS_PRIO|)(all|drop-pkt|deq-pkt|)("CTC_CLI_PP_BMP"|)",
        CTC_CLI_CLEAR_STR,
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_STATS_STR,
        "Service id",
        CTC_CLI_QOS_SERVICE_VAL,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "End port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "All port",
        "Cpu reason",
        "Cpu reason id",
        "End cpu reason",
        "End cpu reason id",
        "All reason",
        CTC_CLI_QOS_QUEUE_STR,
        CTC_CLI_QOS_QUEUE_VAL,
        "Class prioity",
        "Class prioity value",
        "ALL packet",
        "Dropped packet",
        "Deq packet",
        CTC_CLI_PP_BMP_DESC)
{
    int32  ret = CLI_SUCCESS;
    ctc_qos_queue_stats_t stats_param;
    uint8 index = 0;
    uint16 start = 0;
    uint16 end = CTC_QUEUE_NUM_PER_REASON;
    uint16 qid = 0;
    uint32 capability[CTC_GLOBAL_CAPABILITY_MAX] = {0};
    uint32 max_port_num_per_chip = 0;
    uint32 gport_start = 0;
    uint32 gport_end = 0;
    uint16 lport_start = 0;
    uint16 lport_end = 0;
    uint16 loop = 0;
    uint8  loop_flag = 0;
    uint8 gchip = 0;
    uint16 reason_start = 0;
    uint16 reason_end = 0;
    uint8 mchan_index = 0;

    sal_memset(&stats_param, 0, sizeof(ctc_qos_queue_stats_t));

    if(g_ctcs_api_en)
    {
        ret = ctcs_global_ctl_get(g_api_ldev, CTC_GLOBAL_CHIP_CAPABILITY, capability);
    }
    else
    {
        ret = ctc_global_ctl_get(CTC_GLOBAL_CHIP_CAPABILITY, capability);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    max_port_num_per_chip = capability[CTC_GLOBAL_CAPABILITY_MAX_PORT_NUM];

    _ctc_cli_qos_queue_id_parser(vty, &stats_param.queue, &argv[0], argc);

    index = CTC_CLI_GET_ARGC_INDEX("all-port");
    if (0xFF != index)
    {
        stats_param.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;
        lport_start = 0;
        lport_end = max_port_num_per_chip - 1;
        if(g_ctcs_api_en)
        {
            ret = ctcs_get_gchip_id(g_api_ldev, &gchip);
        }
        else
        {
            ret = ctc_get_gchip_id(g_api_ldev, &gchip);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
    }
    else
    {
        index = CTC_CLI_GET_ARGC_INDEX("port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32_RANGE("gport_start", gport_start, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
            mchan_index = CTC_MAP_GPORT_TO_MCHAN_IDX(gport_start);
            gport_end = gport_start;
        }
        index = CTC_CLI_GET_ARGC_INDEX("end-port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32_RANGE("gport_end", gport_end, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        }
        if ((CTC_MAP_GPORT_TO_GCHIP(gport_start) != CTC_MAP_GPORT_TO_GCHIP(gport_end)) || (gport_start > gport_end) || mchan_index != CTC_MAP_GPORT_TO_MCHAN_IDX(gport_end))
        {
            ctc_cli_out("%% GPort range error !\n");
            return CLI_ERROR;
        }
        lport_start = CTC_MAP_GPORT_TO_LPORT(gport_start);
        lport_end = CTC_MAP_GPORT_TO_LPORT(gport_end);
        gchip = CTC_MAP_GPORT_TO_GCHIP(gport_start);
    }

    index = CTC_CLI_GET_ARGC_INDEX("all-reason");
    if (0xFF != index)
    {
        stats_param.queue.queue_type = CTC_QUEUE_TYPE_EXCP_CPU;
        reason_start = 0;
        reason_end = CTC_PKT_CPU_REASON_MAX_COUNT - 1;

    }
    else
    {
        index = CTC_CLI_GET_ARGC_INDEX("reason-id");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT16_RANGE("reason id", reason_start, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
            reason_end = reason_start;
        }
        index = CTC_CLI_GET_ARGC_INDEX("end-reason-id");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT16_RANGE("end reason id", reason_end, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        }
        if (reason_end < reason_start)
        {
            ctc_cli_out("%% Reason id range error !\n");
            return CLI_ERROR;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        start = stats_param.queue.queue_id;
        end = start + 1;
    }

    CTC_CLI_GET_PP_BMP(index, stats_param.pp_bmp);

    index = CTC_CLI_GET_ARGC_INDEX("all");
    if (0xFF != index)
    {
       stats_param.stats_en = 3;
    }

    index = CTC_CLI_GET_ARGC_INDEX("drop-pkt");
    if (0xFF != index)
    {
       stats_param.stats_en = 2;
    }

    index = CTC_CLI_GET_ARGC_INDEX("deq-pkt");
    if (0xFF != index)
    {
       stats_param.stats_en = 1;
    }

    loop_flag = (stats_param.queue.queue_type == CTC_QUEUE_TYPE_EXCP_CPU);
    for(loop = (loop_flag ? reason_start : lport_start); loop <= (loop_flag ? reason_end : lport_end); loop++)
    {
        if (loop_flag)
        {
            stats_param.queue.cpu_reason = loop;
        }
        else
        {
            stats_param.queue.gport = mchan_index ? CTC_MAP_LPORT_TO_GPORT_MCHAN(gchip, loop, mchan_index) : CTC_MAP_LPORT_TO_GPORT(gchip, loop);
        }

        for (qid = start ; qid < end ; qid++)
        {
            stats_param.queue.queue_id = qid;
            if (g_ctcs_api_en)
            {
                ret = ctcs_qos_clear_queue_stats(g_api_ldev, &stats_param);
            }
            else
            {
                ret = ctc_qos_clear_queue_stats(&stats_param);
            }
            if (ret < 0)
            {
                break;
            }
        }
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_set_policer_stats_enable,
        ctc_cli_qos_set_policer_stats_enable_cmd,
        "qos policer stats (enable | disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        CTC_CLI_QOS_STATS_STR,
        "Globally enable QoS policer statistics",
        "Globally disable QoS policer statistics")
{
    bool  enable = FALSE;
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    if (CLI_CLI_STR_EQUAL("e", 0))
    {
        enable = TRUE;
    }
    else
    {
        enable = FALSE;
    }

    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_STATS_EN;
    glb_cfg.u.value = enable ? 1 : 0;

    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_set_port_queue_stats_en,
        ctc_cli_qos_set_port_queue_stats_en_cmd,
        "qos stats" CTC_CLI_QOS_QUEUE_ID_STR "(enable|disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_STATS_STR,
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Enable",
        "Disable")
{
    int32  ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_STATS_EN;

    _ctc_cli_qos_queue_id_parser(vty, &que_cfg.value.stats.queue, &argv[0], argc);


    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        que_cfg.value.stats.stats_en = 1;
    }
    else
    {
        que_cfg.value.stats.stats_en = 0;
    }

    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_get_port_queue_stats_en,
        ctc_cli_qos_get_port_queue_stats_en_cmd,
        "show qos (stats enable|shape pkt-len-adjust)" CTC_CLI_QOS_QUEUE_ID_STR,
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_STATS_STR,
        "Enable",
        CTC_CLI_QOS_SHAPE_STR,
        "Packet Length adjust",
        CTC_CLI_QOS_QUEUE_ID_DSCP)
{
    int32  ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    index = CTC_CLI_GET_ARGC_INDEX("stats");
    if (0xFF != index)
    {
        que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_STATS_EN;
    }
    else
    {
        que_cfg.type = CTC_QOS_QUEUE_CFG_LENGTH_ADJUST;
    }
    _ctc_cli_qos_queue_id_parser(vty, &que_cfg.value.stats.queue, &argv[0], argc);
    if (g_ctcs_api_en)
    {
        ret = ctcs_qos_get_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_get_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if(que_cfg.type == CTC_QOS_QUEUE_CFG_QUEUE_STATS_EN)
    {
        ctc_cli_out("Stats-enable:%d\n",que_cfg.value.stats.stats_en);
    }
    else
    {
        ctc_cli_out("Pkt-len-adjust:%d\n",que_cfg.value.pkt.adjust_len);
    }
    return CLI_SUCCESS;
}
#define cpu_traffic ""

CTC_CLI(ctc_cli_qos_set_cpu_reason_map,
        ctc_cli_qos_set_cpu_reason_map_cmd,
        "qos (cpu-reason REASON) map-to (queue-id QUEUE reason-group GROUP (acl-match-group ACL_MATCH_GP|)|cos COS)",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli show qos cpu-reason",
        "Mapping to",
        "Queue id",
        "<0-7>",
        "Reason group",
        CTC_CLI_QOS_MAX_CPU_REASON_GRP_ID,
        "Acl match group",
        "Group id",
        "Cos",
        "<0-7>")
{
    int32 ret = CLI_SUCCESS;
    uint16 reason_id = 0;
    uint16 queue_id = 0;
    uint8 group_id = 0;
    uint8 acl_match_grp_id = 0;
    uint16 index = 0;
    uint8 cos = 0;

    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    /* Get Cpu Reason Id */
    index = CTC_CLI_GET_ARGC_INDEX("cpu-reason");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[index + 1]);
    }


    /* Get Queue Id */
    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("cos", cos, argv[index + 1]);
        que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_PRIORITY;
        que_cfg.value.reason_pri.cpu_reason = reason_id;
        que_cfg.value.reason_pri.cos = cos;
    }
    else
    {

        /* Get Queue Id */
        index = CTC_CLI_GET_ARGC_INDEX("queue-id");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT8("queue-id", queue_id, argv[index + 1]);
        }

        /* Get Group Id */
        index = CTC_CLI_GET_ARGC_INDEX("reason-group");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT8("reason-group", group_id, argv[index + 1]);
        }

        /* Get ACL Match Group Id */
        index = CTC_CLI_GET_ARGC_INDEX("acl-match-group");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT8("acl-match-group", acl_match_grp_id, argv[index + 1]);
        }
        que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP;
        que_cfg.value.reason_map.cpu_reason = reason_id;
        que_cfg.value.reason_map.queue_id = queue_id;
        que_cfg.value.reason_map.reason_group = group_id;
        que_cfg.value.reason_map.acl_match_group = acl_match_grp_id;
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_set_cpu_reason_dest,
        ctc_cli_qos_set_cpu_reason_dest_cmd,
        "qos cpu-reason REASON dest-to (nexthop NHID | eth-cpu (cpu-port GPORT (sub-index INDEX|)|) | local-cpu  | remote-cpu-port GPORT | local-port GPORT | drop | discard-cancel-to-cpu (enable|disable)) (raw-dest-en|)",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli [show qos cpu-reason]",
        "Destination",
        "Nexthop",
        CTC_CLI_NH_ID_STR,
        "Local CPU by network port",
        "CPU Port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "Sub index",
        "Sub index value",
        "Local CPU",
        "Remote CPU",
        CTC_CLI_GPHYPORT_ID_DESC,
        "Local port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "Drop",
        "Cancel switch logic discard's packet exception to CPU",
        CTC_CLI_ENABLE,
        CTC_CLI_DISABLE,
        "Raw dest gport enable")
{
    int32 ret = CLI_SUCCESS;
    uint16 reason_id = 0;
    uint8 index = 0;
    uint8 sub_index = 0;
    uint8 dest_type = 0;
    uint32 dest_port = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    /* Get Cpu Reason Id */
    CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("local-cpu");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_LOCAL_CPU;
    }

    index = CTC_CLI_GET_ARGC_INDEX("nexthop");
    if (0xFF != index)
    {
       dest_type = CTC_PKT_CPU_REASON_TO_NHID;
       CTC_CLI_GET_UINT32("nexthop", que_cfg.value.reason_dest.nhid, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("eth-cpu");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_LOCAL_CPU_ETH;
        index = CTC_CLI_GET_ARGC_INDEX("cpu-port");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("cpu-port", dest_port, argv[index + 1]);
        }

        index = CTC_CLI_GET_ARGC_INDEX("sub-index");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("sub-index", sub_index, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("remote-cpu-port");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_REMOTE_CPU;
        CTC_CLI_GET_UINT32("remote-cpu port", dest_port, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("local-port");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_LOCAL_PORT;
        CTC_CLI_GET_UINT32("gport", dest_port, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("drop");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_DROP;
    }

    index = CTC_CLI_GET_ARGC_INDEX("discard-cancel-to-cpu");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_DISCARD_CANCEL_TO_CPU;
        if (CLI_CLI_STR_EQUAL("enable", index+1))
        {
            dest_port = 1;
        }
        else
        {
            dest_port = 0;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("raw-dest-en");
    if (0xFF != index)
    {
        que_cfg.value.reason_dest.raw_dest_en = 1;
    }
    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_DEST;
    que_cfg.value.reason_dest.cpu_reason = reason_id;
    que_cfg.value.reason_dest.dest_port = dest_port;
    que_cfg.value.reason_dest.dest_type = dest_type;
    que_cfg.value.reason_dest.sub_index = sub_index;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}
#if 1
CTC_CLI(ctc_cli_qos_set_cpu_reason_misc_param,
        ctc_cli_qos_set_cpu_reason_misc_param_cmd,
        "qos cpu-reason REASON misc-param (truncation (enable|disable) (truncated-len LEN|)|policer POLICER-ID (global-copp|) )",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli [show qos cpu-reason]",
        "cpu reason other misc paramer",
        "Packet will be truncated",
        CTC_CLI_ENABLE,CTC_CLI_DISABLE,
        "Truncate length","length",
        CTC_CLI_QOS_COPP, "Policer id",
        "global copp")
{
    int32 ret = CLI_SUCCESS;
    uint16 reason_id = 0;
    uint8 index = 0;

    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    que_cfg.value.reason_misc.type = CTC_QOS_CPU_REASON_MAX;
    /* Get Cpu Reason Id */
    CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("truncation");
    if (0xFF != index)
    {
        que_cfg.value.reason_misc.type = CTC_QOS_CPU_REASON_TRUNCATION;

        index = CTC_CLI_GET_ARGC_INDEX("enable");
        if (0xFF != index)
        {
            que_cfg.value.reason_misc.truncation_en = 1;

            index = CTC_CLI_GET_ARGC_INDEX("truncated-len");
            if (0xFF != index)
            {
                CTC_CLI_GET_UINT16("truncated-len", que_cfg.value.reason_misc.truncated_len, argv[index + 1]);
            }
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("policer");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("policer-id", que_cfg.value.reason_misc.policer_id, argv[index + 1]);

        index = CTC_CLI_GET_ARGC_INDEX("global-copp");
        if (0xFF != index)
        {
            que_cfg.value.reason_misc.type = CTC_QOS_CPU_REASON_GLOBAL_COPP;
        }
        else
        {
            que_cfg.value.reason_misc.type = CTC_QOS_CPU_REASON_EGRESS_COPP;
        }
    }

    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MISC;
    que_cfg.value.reason_misc.cpu_reason = reason_id;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_qos_get_cpu_reason_misc_param,
        ctc_cli_qos_get_cpu_reason_misc_param_cmd,
        "show qos cpu-reason REASON misc-param (policer (global-copp|) | truncated-len)",
        "Show",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli [show qos cpu-reason]",
        "cpu reason other misc paramer",
        CTC_CLI_QOS_COPP,
        "global copp",
        "Truncate length")
{
    int32 ret = CLI_SUCCESS;
    uint16 reason_id = 0;
    uint8 index = 0;

    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    /* Get Cpu Reason Id */
    CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("global-copp");
    if (0xFF != index)
    {
        que_cfg.value.reason_misc.type = CTC_QOS_CPU_REASON_GLOBAL_COPP;
    }

    index = CTC_CLI_GET_ARGC_INDEX("truncated-len");
    if (0xFF != index)
    {
        que_cfg.value.reason_misc.type = CTC_QOS_CPU_REASON_TRUNCATION;

    }

    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MISC;
    que_cfg.value.reason_misc.cpu_reason = reason_id;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_get_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("Cpu-reason      : %d\n", que_cfg.value.reason_misc.cpu_reason);
    if(que_cfg.value.reason_misc.type == CTC_QOS_CPU_REASON_TRUNCATION)
    {
        ctc_cli_out("Truncated-len   : %d\n", que_cfg.value.reason_misc.truncated_len);
    }
    else if(que_cfg.value.reason_misc.type == CTC_QOS_CPU_REASON_GLOBAL_COPP
        || que_cfg.value.reason_misc.type == CTC_QOS_CPU_REASON_EGRESS_COPP)
    {
        ctc_cli_out("global-copp     : %d\n", que_cfg.value.reason_misc.type);
        ctc_cli_out("Policer-id      : %d\n", que_cfg.value.reason_misc.policer_id);
    }
    return ret;
}
#else
CTC_CLI(ctc_cli_qos_set_cpu_reason_misc_param,
        ctc_cli_qos_set_cpu_reason_misc_param_cmd,
        "qos cpu-reason REASON misc-param truncation (enable|disable)",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli [show qos cpu-reason]",
        "cpu reason other misc paramer",
        "Packet will be truncated",
        CTC_CLI_ENABLE,CTC_CLI_DISABLE)
{
    int32 ret = CLI_SUCCESS;
    uint16 reason_id = 0;
    uint8 index = 0;
    uint32 value = 0;

    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    /* Get Cpu Reason Id */
    CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
      value = 1;
    }

    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MISC;
    que_cfg.value.reason_misc.cpu_reason = reason_id;
    que_cfg.value.reason_misc.truncation_en= value;

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}
#endif
CTC_CLI(ctc_cli_qos_set_reason_truncation_len,
        ctc_cli_qos_set_reason_truncation_len_cmd,
        "qos cpu-reason truncation-length LENGTH",
        CTC_CLI_QOS_STR,
        "Cpu Resaon ",
        "The length of truncation",
        "The length of truncation ")
{
    int32 ret = CLI_SUCCESS;
    int32 value = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    CTC_CLI_GET_UINT32("truncation-length", value, argv[0]);
    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_TRUNCATION_LEN;
    glb_cfg.u.value  = value;
    if(g_ctcs_api_en)
    {
         ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}
CTC_CLI(ctc_cli_qos_set_reason_shp_base_pkt,
        ctc_cli_qos_set_reason_shp_base_pkt_cmd,
        "qos shape (reason-shape-pkt | port-shape-pkt) (enable | disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "CPU Shape base on packet",
        "Network port shape base on packet",
        "Globally enable ",
        "Globally disable")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t glb_cfg;
    uint8 index = 0;
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    index = CTC_CLI_GET_ARGC_INDEX("reason-shape-pkt");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_REASON_SHAPE_PKT_EN;
    }
    else
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_SHAPE_PKT_EN;
    }
    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        glb_cfg.u.value = 1;
    }
    else
    {
        glb_cfg.u.value = 0;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_qos_set_queue_shape_base,
        ctc_cli_qos_set_queue_shape_base_cmd,
        "qos shape (port | group |queue) (enable | disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "port shape",
        "queue shape",
        "group shape",
        "Globally enable ",
        "Globally disable")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t glb_cfg;
    uint8 index = 0;
    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_PORT_SHAPE_EN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("group");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_GROUP_SHAPE_EN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue");
    if (0xFF != index)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_QUE_SHAPE_EN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        glb_cfg.u.value = 1;
    }
    else
    {
        glb_cfg.u.value = 0;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}
CTC_CLI(ctc_cli_qos_get_cpu_reason,
        ctc_cli_qos_get_cpu_reason_cmd,
        "show qos (cpu-reason REASON) (map-to-queue-info |dest-info)",
        "Show",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli show qos cpu-reason>",
        "Mapping to queue info",
        "Dest info")
{
    int32 ret = CLI_SUCCESS;
    uint16 cpu_reason = 0;
    uint8 type = 0;
    uint16 index = 0;
    char* dest_type[7] = {"local-cpu","local-port","remote-cpu","drop","nexthop","local-cpu-eth","cancel-cpu"};
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    /* Get Cpu Reason Id */
    index = CTC_CLI_GET_ARGC_INDEX("cpu-reason");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("cpu-reason", cpu_reason, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("map-to-queue-info");
    if (0xFF != index)
    {
        type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP;
        que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP;
        que_cfg.value.reason_map.cpu_reason = cpu_reason;
    }
    else
    {
        type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_DEST;
        que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_DEST;
        que_cfg.value.reason_dest.cpu_reason = cpu_reason;
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_get_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    if(type == CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP)
    {
        ctc_cli_out("Cpu-reason      : %d\n", que_cfg.value.reason_map.cpu_reason);
        ctc_cli_out("Queue-id        : %d\n", que_cfg.value.reason_map.queue_id);
        ctc_cli_out("Group-id        : %d\n", que_cfg.value.reason_map.reason_group);
        ctc_cli_out("ACL-Match-group : %d\n", que_cfg.value.reason_map.acl_match_group);
    }
    else
    {
        ctc_cli_out("Cpu-reason      : %d\n", que_cfg.value.reason_dest.cpu_reason);
        ctc_cli_out("Dest-type       : %s\n", dest_type[que_cfg.value.reason_dest.dest_type]);
        if(que_cfg.value.reason_dest.dest_type == CTC_PKT_CPU_REASON_TO_NHID)
        {
            ctc_cli_out("Nexthop-id      : %d\n", que_cfg.value.reason_dest.nhid);
        }
        else
        {
            ctc_cli_out("Port            : 0x%x\n", que_cfg.value.reason_dest.dest_port);
        }
        ctc_cli_out("Raw-dest-en     : %d\n", que_cfg.value.reason_dest.raw_dest_en);
    }
    return ret;
}

#define service_cli ""
CTC_CLI(ctc_cli_qos_add_del_service,
        ctc_cli_qos_add_del_service_cmd,
        "qos service (create | destroy) (service-id SERVICE) ",
        CTC_CLI_QOS_STR,
        "Service",
        "Binding queue",
        "Unbinding queue",
        "Serive id",
        CTC_CLI_QOS_SERVICE_VAL)
{
    int32 ret = CLI_SUCCESS;
    uint16 service_id = 0;
    uint8 index = 0;
    ctc_qos_queue_cfg_t que_cfg;
    ctc_qos_service_info_t srv_queue_info;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    sal_memset(&srv_queue_info, 0, sizeof(ctc_qos_service_info_t));


    index = CTC_CLI_GET_ARGC_INDEX("create");
    if (0xFF != index)
    {
       srv_queue_info.opcode = CTC_QOS_SERVICE_ID_CREATE;
    }

    index = CTC_CLI_GET_ARGC_INDEX("destroy");
    if (0xFF != index)
    {
       srv_queue_info.opcode = CTC_QOS_SERVICE_ID_DESTROY;
    }

    index = CTC_CLI_GET_ARGC_INDEX("service-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("service-id", service_id, argv[index + 1]);
    }

    srv_queue_info.service_id = service_id;

    sal_memcpy(&que_cfg.value.srv_queue_info, &srv_queue_info, sizeof(srv_queue_info));

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


CTC_CLI(ctc_cli_qos_bind_service,
        ctc_cli_qos_bind_service_cmd,
        "qos service  (bind | unbind) (service-id SERVICE dest-port GPORT) (queue-id QUEUE|) (egress|) \
        ( mode MODE (logic-port LOGIC_PORT | dsnh-offset OFFSET|) (dsnh-offset-shift SHIFT|) |) \
        (hsch-en| offset OFFSET|)",
        CTC_CLI_QOS_STR,
        "Service",
        "Binding queue",
        "Unbinding queue",
        "Serive id",
        CTC_CLI_QOS_SERVICE_VAL,
        "Dest port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "Queue id",
        "Queue id value",
        "Egress direction",
        "Enq mode",
        "Enq mode value",
        "Loigc port",
        "Loigc port value",
        "The dsnh offset, allocated by user",
        "Offset",
        "The dsnh offset shift, use dsnh offset >> dsnh offset shift as enq key",
        "Shift",
        "Hierarchical sch enable",
        "Offset",
        "Offset value")
{
    int32 ret = CLI_SUCCESS;
    uint16 service_id = 0;
    uint16 dest_port = 0;
    uint8 index = 0;
    ctc_qos_queue_cfg_t que_cfg;
    ctc_qos_service_info_t srv_queue_info;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    sal_memset(&srv_queue_info, 0, sizeof(ctc_qos_service_info_t));


    index = CTC_CLI_GET_ARGC_INDEX("bind");
    if (0xFF != index)
    {
       srv_queue_info.opcode = CTC_QOS_SERVICE_ID_BIND_DESTPORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("unbind");
    if (0xFF != index)
    {
       srv_queue_info.opcode = CTC_QOS_SERVICE_ID_UNBIND_DESTPORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("service-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("service-id", service_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("dest-port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", dest_port, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("egress");
    if (0xFF != index)
    {
        srv_queue_info.dir = CTC_EGRESS;
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        SET_FLAG(srv_queue_info.flag, CTC_QOS_SERVICE_FLAG_QID_EN);
        CTC_CLI_GET_UINT16("queue-id", srv_queue_info.queue_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("mode");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("mode", srv_queue_info.mode, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("logic-port", srv_queue_info.logic_port, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("dsnh-offset");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("dsnh-offset", srv_queue_info.dsnh_offset, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("dsnh-offset-shift");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("dsnh-offset-shift", srv_queue_info.dsnh_offset_shift, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("hsch-en");
    if (0xFF != index)
    {
        SET_FLAG(srv_queue_info.flag, CTC_QOS_SERVICE_FLAG_HSCH_EN);
    }
    index = CTC_CLI_GET_ARGC_INDEX("offset");
    if (0xFF != index)
    {
        SET_FLAG(srv_queue_info.flag, CTC_QOS_SERVICE_FLAG_OOBFC_EN);
        CTC_CLI_GET_UINT16("offset", srv_queue_info.oobfc_offset, argv[index + 1]);
    }
    srv_queue_info.service_id = service_id;
    srv_queue_info.gport = dest_port;

    sal_memcpy(&que_cfg.value.srv_queue_info, &srv_queue_info, sizeof(srv_queue_info));

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}
#define monitor_drop_cli ""
CTC_CLI(ctc_cli_qos_monitor_drop,
        ctc_cli_qos_monitor_drop_cmd,
        "qos monitor-drop (src-port GPHYPORT_ID (pri-class-bmp PRI_CLASS_BITMAP|))(dst-port GPHYPORT_ID | nhid NHID )(enable (rate RATE|)|disable)",
        CTC_CLI_QOS_STR,
        "Queue monitor drop",
        "Source global port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "Priority class bitmap",
        "Priority class bitmap value",
        "Destination global port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "Nexthop id",
        "Nexthop id value",
        "Enable",
        "Rate, percent:1 / (2^rate)",
        "Rate Value",
        "Disable")
{
    int32 ret = CLI_SUCCESS;
    uint32 port = 0;
    uint8 index = 0;
    uint8 bmp = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_QUEUE_DROP_MONITOR_EN;
    index = CTC_CLI_GET_ARGC_INDEX("src-port");
    if (0xFF != index)
    {
       CTC_CLI_GET_UINT32("gport", port, argv[index + 1]);
       glb_cfg.u.drop_monitor.src_gport = port;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pri-class-bmp");
    if (0xFF != index)
    {
       CTC_CLI_GET_UINT8("pri-class-bmp", bmp, argv[index + 1]);
       glb_cfg.u.drop_monitor.pri_class_bmp = bmp;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dst-port");
    if (0xFF != index)
    {
       CTC_CLI_GET_UINT32("gport", port, argv[index + 1]);
       glb_cfg.u.drop_monitor.dst_gport = port;
    }

    index = CTC_CLI_GET_ARGC_INDEX("nhid");
    if (0xFF != index)
    {
       CTC_CLI_GET_UINT32("nhid", port, argv[index + 1]);
       glb_cfg.u.drop_monitor.nhid = port;
    }
    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        glb_cfg.u.drop_monitor.enable = 1;
    }
    index = CTC_CLI_GET_ARGC_INDEX("rate");
    if (0xFF != index)
    {
       CTC_CLI_GET_UINT8("rate", glb_cfg.u.drop_monitor.rate, argv[index + 1]);
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}

CTC_CLI(ctc_cli_qos_show_monitor_drop,
        ctc_cli_qos_show_monitor_drop_cmd,
        "show qos monitor-drop (src-port GPHYPORT_ID )",
        "Show",
        CTC_CLI_QOS_STR,
        "Queue monitor drop",
        "Source global port",
        CTC_CLI_GPHYPORT_ID_DESC)
{
    int32 ret = CLI_SUCCESS;
    uint32 port = 0;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_QUEUE_DROP_MONITOR_EN;
    index = CTC_CLI_GET_ARGC_INDEX("src-port");
    if (0xFF != index)
    {
       CTC_CLI_GET_UINT32("gport", port, argv[index + 1]);
       glb_cfg.u.drop_monitor.src_gport = port;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_get_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("\nMonitor Drop Information:\n");
    ctc_cli_out("%-10s %-10s %-13s %-10s\n","enable", "dst-port", "pri-class-bmp", "rate");
    ctc_cli_out("-------------------------------------------------\n");
    ctc_cli_out("%-10d 0x%-8x 0x%-11x %-10d\n",glb_cfg.u.drop_monitor.enable,glb_cfg.u.drop_monitor.dst_gport, glb_cfg.u.drop_monitor.pri_class_bmp, glb_cfg.u.drop_monitor.rate);
    return ret;
}

#define oobfc_cli ""
CTC_CLI(ctc_cli_qos_set_oobfc,
        ctc_cli_qos_set_oobfc_cmd,
        "qos oobfc mode MODE (priority|)(("CTC_CLI_PORT_BITMAP_STR"|"CTC_CLI_PORT_BITMAP_ARRAY_STR")(gchip GCHIP_ID|) (offset OFFSET|)|) (enable|disable)",
        CTC_CLI_QOS_STR,
        "Out of band flow control",
        "Mode",
        "Mode value,0:tx-egr,1:tx-igr,2:rx-egr,3:rx-igr",
        "Priority flow control",
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_DESC,
        CTC_CLI_PORT_BITMAP_VALUE_DESC,
        CTC_CLI_PORT_BITMAP_ARRAY_DESC,
        CTC_CLI_GCHIP_DESC,
        CTC_CLI_GCHIP_ID_DESC,
        "Port offset in port group map",
        "Offset value",
        "Enable",
        "Disable")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;
    uint32 max_num = CTC_PORT_BITMAP_IN_WORD;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_OOBFC;
    CTC_CLI_GET_UINT8("mode", glb_cfg.u.oobfc.mode, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (index != 0xFF)
    {
        glb_cfg.u.oobfc.is_pfc = 1;
    }

    CTC_CLI_PORT_BITMAP_GET(glb_cfg.u.oobfc.port_bitmap);
    index = CTC_CLI_GET_ARGC_INDEX("array-bmp");
    if(index != 0xFF)
    {
    	CTC_CLI_GET_UINT32_ARRAY("array-bmp", glb_cfg.u.oobfc.port_bitmap, &max_num, argv[index + 1], ret);
    }
    index = CTC_CLI_GET_ARGC_INDEX("gchip");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8("gchip", glb_cfg.u.oobfc.gchip_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("offset");
    if (index != 0xFF)
    {

        CTC_CLI_GET_UINT8("offset", glb_cfg.u.oobfc.port_offset, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        glb_cfg.u.oobfc.enable = 1;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}

CTC_CLI(ctc_cli_qos_show_oobfc,
        ctc_cli_qos_show_oobfc_cmd,
        "show qos oobfc mode MODE (priority|)(gchip GCHIP_ID|)",
        "Show",
        CTC_CLI_QOS_STR,
        "Out of band flow control",
        "Mode",
        "Mode value,0:tx-egr,1:tx-igr,2:rx-egr,3:rx-igr",
        "Priority flow control",
        CTC_CLI_GCHIP_DESC,
        CTC_CLI_GCHIP_ID_DESC)
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_OOBFC;
    index = CTC_CLI_GET_ARGC_INDEX("mode");
    CTC_CLI_GET_UINT8("mode", glb_cfg.u.oobfc.mode, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (index != 0xFF)
    {
        glb_cfg.u.oobfc.is_pfc = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("gchip");
    if (index != 0xFF)
    {

        CTC_CLI_GET_UINT8("gchip", glb_cfg.u.oobfc.gchip_id, argv[index + 1]);
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_get_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("\nOobfc Information:\n");
    ctc_cli_out("%-24s:  %u\n", "enable", glb_cfg.u.oobfc.enable);
    if(glb_cfg.u.oobfc.mode == CTC_QOS_OOBFC_MODE_TX_EGRESS
        || glb_cfg.u.oobfc.mode == CTC_QOS_OOBFC_MODE_TX_INGRESS)
    {
    ctc_cli_out("%-24s:  %u\n", "gchip", glb_cfg.u.oobfc.gchip_id);
    ctc_cli_out("%-24s:  %u\n", "offset", glb_cfg.u.oobfc.port_offset);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp0", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[0]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp1", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[1]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp2", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[2]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp3", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[3]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp4", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[4]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp5", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[5]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp6", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[6]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp7", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[7]);
    if (MAX_PORT_NUM_PER_CHIP > 256)
    {
    ctc_cli_out("%-24s:  0x%x\n", "pbmp8", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[8]);
    ctc_cli_out("%-24s:  0x%x\n", "pbmp9", ((uint32*)glb_cfg.u.oobfc.port_bitmap)[9]);
    }
    }
    return ret;
}

CTC_CLI(ctc_cli_qos_set_glb_cfg,
        ctc_cli_qos_set_glb_cfg_cmd,
        "qos global-cfg (fast-ecn threshold THRD|round-trip mode Mode)",
        CTC_CLI_QOS_STR,
        "Global config",
        "Fast ECN",
        "Threshold",
        "Threshold value",
        "Round trip buffer",
        "Global mode of Round trip buffer",
        "Mode value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    index = CTC_CLI_GET_ARGC_INDEX("fast-ecn");
    if (index != 0xFF)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_FAST_ECN_THRD;
        CTC_CLI_GET_UINT32("thrd", glb_cfg.u.value, argv[index + 2]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("round-trip");
    if (index != 0xFF)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_ROUND_TRIP_MODE;
        CTC_CLI_GET_UINT32("mode", glb_cfg.u.value, argv[index + 2]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_get_glb_cfg,
        ctc_cli_qos_get_glb_cfg_cmd,
        "show qos global-cfg (fast-ecn|round-trip)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_QOS_STR,
        "Global config",
        "Fast ECN",
        "Round trip buffer")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    index = CTC_CLI_GET_ARGC_INDEX("fast-ecn");
    if (index != 0xFF)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_FAST_ECN_THRD;
    }

    index = CTC_CLI_GET_ARGC_INDEX("round-trip");
    if (index != 0xFF)
    {
        glb_cfg.cfg_type = CTC_QOS_GLB_CFG_ROUND_TRIP_MODE;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_get_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if(glb_cfg.cfg_type == CTC_QOS_GLB_CFG_FAST_ECN_THRD)
    {
        ctc_cli_out("%-10s\n", "Fast-ECN information");
        ctc_cli_out("----------------\n");
        ctc_cli_out("%-19s : %-8u\n","Threshold:", glb_cfg.u.value);
        ctc_cli_out("----------------\n");
    }
    if(glb_cfg.cfg_type == CTC_QOS_GLB_CFG_ROUND_TRIP_MODE)
    {
        ctc_cli_out("%-10s\n", "Round-Trip information");
        ctc_cli_out("----------------\n");
        ctc_cli_out("%-19s : %-8u\n","mode:", glb_cfg.u.value);
        ctc_cli_out("----------------\n");
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_qos_query_stats,
        ctc_cli_qos_query_stats_cmd,
        "show qos stats type (drop-monitor|port PORT prio-class PRIO_CLASS)",
        "Show",
        CTC_CLI_QOS_STR,
        "Stats",
        "Type",
        "Drop moitor",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Priority class",
        "Priority class Value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_stats_type_t type = CTC_QOS_STATS_TYPE_MAX;
    void* p_stats = NULL;
    ctc_qos_prio_class_stats_t prio_class_stats;
    ctc_qos_stats_info_t qos_stats;
    ctc_qos_stats_info_t* p_stats_print = NULL;

    sal_memset(&prio_class_stats, 0, sizeof(ctc_qos_prio_class_stats_t));
    sal_memset(&qos_stats, 0, sizeof(ctc_qos_stats_info_t));
    index = CTC_CLI_GET_ARGC_INDEX("drop-monitor");
    if (index != 0xFF)
    {
        type = CTC_QOS_STATS_TYPE_DROP_MONITOR;
        p_stats = &qos_stats;
        p_stats_print = &qos_stats;
    }
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (index != 0xFF)
    {
        type = CTC_QOS_STATS_TYPE_PRIO_CLASS;
        CTC_CLI_GET_UINT32("gport", prio_class_stats.gport, argv[index + 1]);
        CTC_CLI_GET_UINT8("prio class", prio_class_stats.prio_class, argv[index + 3]);
        p_stats = &prio_class_stats;
        p_stats_print = &prio_class_stats.stats;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_query_stats(g_api_ldev, type, p_stats);
    }
    else
    {
        ret = ctc_qos_query_stats(type, p_stats);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if (CTC_QOS_STATS_TYPE_PRIO_CLASS == type)
    {
        ctc_cli_out("port:0x%04x, prio-class:%d Stats:\n", prio_class_stats.gport, prio_class_stats.prio_class);
    }
    else
    {
        ctc_cli_out("Drop Monitor Stats:\n");
    }
    ctc_cli_out("----------------------------------------------\n");
    ctc_cli_out("%-20s: %"PRIu64"\n", "deq_packets", p_stats_print?p_stats_print->deq_packets:0);
    ctc_cli_out("%-20s: %"PRIu64"\n", "drop_packets", p_stats_print?p_stats_print->drop_packets:0);
    return ret;
}
CTC_CLI(ctc_cli_qos_clear_stats,
        ctc_cli_qos_clear_stats_cmd,
        "clear qos stats type (drop-monitor|port PORT prio-class PRIO_CLASS)",
        "Clear",
        CTC_CLI_QOS_STR,
        "Stats",
        "Type",
        "Drop moitor",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Priority class",
        "Priority class Value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_stats_type_t type = CTC_QOS_STATS_TYPE_MAX;
    void* p_stats = NULL;
    ctc_qos_prio_class_stats_t prio_class_stats;

    sal_memset(&prio_class_stats, 0, sizeof(ctc_qos_prio_class_stats_t));
    index = CTC_CLI_GET_ARGC_INDEX("drop-monitor");
    if (index != 0xFF)
    {
        type = CTC_QOS_STATS_TYPE_DROP_MONITOR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (index != 0xFF)
    {
        type = CTC_QOS_STATS_TYPE_PRIO_CLASS;
        CTC_CLI_GET_UINT32("gport", prio_class_stats.gport, argv[index + 1]);
        CTC_CLI_GET_UINT8("prio class", prio_class_stats.prio_class, argv[index + 3]);
        p_stats = &prio_class_stats;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_clear_stats(g_api_ldev, type, p_stats);
    }
    else
    {
        ret = ctc_qos_clear_stats(type, p_stats);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}


int32
ctc_cli_qos_init(ctc_vti_t* vty)
{
    if (CTC_VTY_CLIENT(vty)->flexq_profile == NULL)
    {
        CTC_VTY_CLIENT(vty)->flexq_profile = mem_malloc(MEM_CLI_MODULE, CTC_QOS_FLEXQ_MAP_PROFILE*sizeof(ctc_qos_queue_enq_t));
        if (!CTC_VTY_CLIENT(vty)->flexq_profile) { return CLI_ERROR; }
        sal_memset(CTC_VTY_CLIENT(vty)->flexq_profile, 0, CTC_QOS_FLEXQ_MAP_PROFILE*sizeof(ctc_qos_queue_enq_t));
    }
    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_qos_flexq_map_profile,
        ctc_cli_qos_flexq_map_profile_cmd,
        "qos flexq-profile (remove|num NUM) {q-base [Q_BASE] | ucq-num [UCQ_NUM] | mcq-num [UCQ_NUM] | pkt-type [PKT_TYPE] | class-prio [CLASS_PRIO] | sched-mode [SCHED_MODE]| enq-mode [ENQ_MODE]|}",
        CTC_CLI_QOS_STR,
        "Flex queue profile",
        "Remove profile",
        "Number",
        "Number Value",
        "Queue base",
        "Queue base array",
        "Ucq number",
        "Ucq number array",
        "Mcq number",
        "Mcq number array",
        "Packet type",
        "Packet Type array",
        "Class prioity",
        "Class prioity array",
        "Schedule mode",
        "Schedule mode array",
        "Enque mode",
        "Enque mode array")
{
    int32 ret = CLI_SUCCESS;
    uint8* arr_q_base = NULL;
    uint8* arr_ucq_num = NULL;
    uint8* arr_mcq_num = NULL;
    uint32* arr_pkt_type = NULL;
    uint8* arr_class_prio = NULL;
    uint8* arr_sched_mode = NULL;
    uint8* arr_enq_mode = NULL;
    uint32 arr_num = 0;
    uint8 profile_num = 0;
    uint8 index = 0;

    
    index = CTC_CLI_GET_ARGC_INDEX("num");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8("flexq-profile-num", profile_num, argv[index + 1]);
    }
    
    if (profile_num == 0)
    {
        ctc_cli_out("%% %s \n", " No memory \n");
        goto error_return;
    }
    ret = ctc_cli_qos_init(vty);
    if (ret == CLI_ERROR)
    {
        ctc_cli_out("%% %s \n", " No memory \n");
        return CTC_E_NO_MEMORY;
    }
  
    CTC_VTY_CLIENT(vty)->flexq_profile_num = profile_num;
    index = CTC_CLI_GET_ARGC_INDEX("q-base");
    if (index != 0xFF)
    {
        arr_num = profile_num;
        arr_q_base = mem_malloc(MEM_CLI_MODULE, arr_num * sizeof(uint8));
        if (NULL == arr_q_base)
        {
            ctc_cli_out("No memory.\n");
            goto error_return;
        }
        sal_memset(arr_q_base, 0, arr_num * sizeof(uint8));
        CTC_CLI_GET_UINT8_ARRAY(argv[index], arr_q_base, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            goto error_return;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("ucq-num");
    if (index != 0xFF)
    {
        arr_num = profile_num;
        arr_ucq_num = mem_malloc(MEM_CLI_MODULE, arr_num * sizeof(uint8));
        if (NULL == arr_ucq_num)
        {
            ctc_cli_out("No memory.\n");
            goto error_return;
        }
        sal_memset(arr_ucq_num, 0, arr_num * sizeof(uint8));
        CTC_CLI_GET_UINT8_ARRAY(argv[index], arr_ucq_num, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            goto error_return;
        }
    }
    index = CTC_CLI_GET_ARGC_INDEX("mcq-num");
    if (index != 0xFF)
    {
        arr_num = profile_num;
        arr_mcq_num = mem_malloc(MEM_CLI_MODULE, arr_num * sizeof(uint8));
        if (NULL == arr_mcq_num)
        {
            ctc_cli_out("No memory.\n");
            goto error_return;
        }
        sal_memset(arr_mcq_num, 0, arr_num * sizeof(uint8));
        CTC_CLI_GET_UINT8_ARRAY(argv[index], arr_mcq_num, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            goto error_return;
        }
    }
    index = CTC_CLI_GET_ARGC_INDEX("pkt-type");
    if (index != 0xFF)
    {
        arr_num = profile_num;
        arr_pkt_type = mem_malloc(MEM_CLI_MODULE, arr_num * sizeof(uint32));
        if (NULL == arr_pkt_type)
        {
            ctc_cli_out("No memory.\n");
            goto error_return;
        }
        sal_memset(arr_pkt_type, 0, arr_num * sizeof(uint32));
        CTC_CLI_GET_UINT32_ARRAY(argv[index], arr_pkt_type, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            goto error_return;
        }
    }
    index = CTC_CLI_GET_ARGC_INDEX("class-prio");
    if (index != 0xFF)
    {
        arr_num = profile_num;
        arr_class_prio = mem_malloc(MEM_CLI_MODULE, arr_num * sizeof(uint8));
        if (NULL == arr_class_prio)
        {
            ctc_cli_out("No memory.\n");
            goto error_return;
        }
        sal_memset(arr_class_prio, 0, arr_num * sizeof(uint8));
        CTC_CLI_GET_UINT8_ARRAY(argv[index], arr_class_prio, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            goto error_return;
        }
    }
    index = CTC_CLI_GET_ARGC_INDEX("sched-mode");
    if (index != 0xFF)
    {
        arr_num = profile_num;
        arr_sched_mode = mem_malloc(MEM_CLI_MODULE, arr_num * sizeof(uint8));
        if (NULL == arr_sched_mode)
        {
            ctc_cli_out("No memory.\n");
            goto error_return;
        }
        sal_memset(arr_sched_mode, 0, arr_num * sizeof(uint8));
        CTC_CLI_GET_UINT8_ARRAY(argv[index], arr_sched_mode, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            goto error_return;
        }
    }
    index = CTC_CLI_GET_ARGC_INDEX("enq-mode");
    if (index != 0xFF)
    {
        arr_num = profile_num;
        arr_enq_mode = mem_malloc(MEM_CLI_MODULE, arr_num * sizeof(uint8));
        if (NULL == arr_enq_mode)
        {
            ctc_cli_out("No memory.\n");
            goto error_return;
        }
        sal_memset(arr_enq_mode, 0, arr_num * sizeof(uint8));
        CTC_CLI_GET_UINT8_ARRAY(argv[index], arr_enq_mode, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            goto error_return;
        }
    }

    for (index = 0; index < CTC_VTY_CLIENT(vty)->flexq_profile_num; index++)
    {
        if (arr_pkt_type)
        {
            ((ctc_qos_queue_enq_t*)CTC_VTY_CLIENT(vty)->flexq_profile)[index].pkt_type = arr_pkt_type[index];
        }
        if (arr_q_base)
        {
            ((ctc_qos_queue_enq_t*)CTC_VTY_CLIENT(vty)->flexq_profile)[index].q_base = arr_q_base[index];
        }
        if (arr_ucq_num)
        {
            ((ctc_qos_queue_enq_t*)CTC_VTY_CLIENT(vty)->flexq_profile)[index].ucq_num = arr_ucq_num[index];
        }
        if (arr_mcq_num)
        {
            ((ctc_qos_queue_enq_t*)CTC_VTY_CLIENT(vty)->flexq_profile)[index].mcq_num = arr_mcq_num[index];
        }
        if (arr_enq_mode)
        {
            ((ctc_qos_queue_enq_t*)CTC_VTY_CLIENT(vty)->flexq_profile)[index].enq_mode = arr_enq_mode[index];
        }
        if (arr_class_prio)
        {
            ((ctc_qos_queue_enq_t*)CTC_VTY_CLIENT(vty)->flexq_profile)[index].class_prio = arr_class_prio[index];
        }
        if (arr_sched_mode)
        {
            ((ctc_qos_queue_enq_t*)CTC_VTY_CLIENT(vty)->flexq_profile)[index].sched_mode = arr_sched_mode[index];
        }
    }

error_return:
    mem_free(arr_q_base);
    mem_free(arr_ucq_num);
    mem_free(arr_mcq_num);
    mem_free(arr_pkt_type);
    mem_free(arr_class_prio);
    mem_free(arr_sched_mode);
    mem_free(arr_enq_mode);
    return ret;
}

CTC_CLI(ctc_cli_qos_flexq_map,
        ctc_cli_qos_flexq_map_cmd,
        "qos flexq (port-bmp [PORT_BMP] | port GPORT |) mode (fixed|flex)",
        CTC_CLI_QOS_STR,
        "Queue",
        "Port bitmap",
        "Port bitmap array",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Mode",
        "Fixed mode",
        "Flex mode")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint32 arr_num = CTC_PORT_BITMAP_IN_WORD;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_MAP;
    index = CTC_CLI_GET_ARGC_INDEX("port-bmp");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_ARRAY(argv[index], que_cfg.value.que_map.port_bmp, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            return CLI_ERROR;
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", que_cfg.value.que_map.gport, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("flex");
    if (index != 0xFF)
    {
        que_cfg.value.que_map.mode = CTC_QOS_PORT_QUEUE_FLEX_MODE;
        que_cfg.value.que_map.enq_num = CTC_VTY_CLIENT(vty)->flexq_profile_num;
        que_cfg.value.que_map.enq = CTC_VTY_CLIENT(vty)->flexq_profile;
    }
    else
    {
        que_cfg.value.que_map.mode = CTC_QOS_PORT_QUEUE_FIXED_MODE;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_set_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}

CTC_CLI(ctc_cli_qos_show_flexq_map,
        ctc_cli_qos_show_flexq_map_cmd,
        "show qos flexq  (port-bmp [PORT_BMP]| port GPORT |)",
        "Show",
        CTC_CLI_QOS_STR,
        "Flwxq",
        "Port bitmap",
        "Port bitmap array",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC)
{
    int32 ret = CLI_SUCCESS;
    uint32 arr_num = CTC_PORT_BITMAP_IN_WORD;
    ctc_qos_queue_cfg_t que_cfg;
    ctc_qos_queue_enq_t* p_enq;
    uint8 index = 0;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_MAP;
    index = CTC_CLI_GET_ARGC_INDEX("port-bmp");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_ARRAY(argv[index], que_cfg.value.que_map.port_bmp, &arr_num, argv[index + 1], ret);
        if (ret != CLI_SUCCESS)
        {
            return CLI_ERROR;
        }
    }
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("gport", que_cfg.value.que_map.gport, argv[index + 1]);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_get_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    que_cfg.value.que_map.enq = mem_malloc(MEM_CLI_MODULE, que_cfg.value.que_map.enq_num * sizeof(ctc_qos_queue_enq_t));
    if (NULL == que_cfg.value.que_map.enq)
    {
        ctc_cli_out("No memory.\n");
        return CLI_ERROR;
    }
    sal_memset(que_cfg.value.que_map.enq, 0, que_cfg.value.que_map.enq_num * sizeof(ctc_qos_queue_enq_t));
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_queue(g_api_ldev, &que_cfg);
    }
    else
    {
        ret = ctc_qos_get_queue(&que_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("%-5s %-6s %-7s %-7s %-10s %-10s %-10s\n", "No.", "q_base", "ucq_num", "mcq_num", "class_prio", "sched_mode", "pkt_type");
    ctc_cli_out("----------------------------------------------------------------\n");
    for (index = 0; index < que_cfg.value.que_map.enq_num; index++)
    {
        p_enq = &que_cfg.value.que_map.enq[index];
        ctc_cli_out("%-5d %-6d %-7d %-7d %-10d %-10d 0x%08x\n", index, p_enq->q_base, p_enq->ucq_num, p_enq->mcq_num, p_enq->class_prio, p_enq->sched_mode, p_enq->pkt_type);
    }
    mem_free(que_cfg.value.que_map.enq);
    return CLI_SUCCESS;
}

#ifdef EFC_BK
CTC_CLI(ctc_cli_qos_set_efc_cfg,
        ctc_cli_qos_set_efc_cfg_cmd,
        "qos efc type (all|low|mid|high) {pri-mode PRI_MODE | pri-mask PRI_MASK | interval INTERVAL | nh-id NH_ID | chip-id CHIP_ID}",
        CTC_CLI_QOS_STR,
        "Enhance flow control",
        "Type",
        "All type",
        "Low congistion level type",
        "Mid congistion level type",
        "High congistion level type",
        "Pri mode",
        "Pri mode value",
        "Pri mask",
        "Pri mask value",
        "Interval",
        "Interval value, units:us",
        "Nexthop id",
        "Nexthop ID",
        "Chip ID",
        "Chip ID value")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_EFC_CFG;

    if (CLI_CLI_STR_EQUAL("low", 0))
    {
        glb_cfg.u.efc.type = CTC_QOS_EFC_TYPE_LOW;
    }
    else if (CLI_CLI_STR_EQUAL("mid", 0))
    {
        glb_cfg.u.efc.type = CTC_QOS_EFC_TYPE_MID;
    }
    else if (CLI_CLI_STR_EQUAL("high", 0))
    {
        glb_cfg.u.efc.type = CTC_QOS_EFC_TYPE_HIGH;
    }
    else
    {
        glb_cfg.u.efc.type = CTC_QOS_EFC_TYPE_NONE; /*means all*/
    }

    index = CTC_CLI_GET_ARGC_INDEX("pri-mode");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8("pri mode", glb_cfg.u.efc.pri_mode, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("pri-mask");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8("pri mask", glb_cfg.u.efc.pri_mask, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("interval");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32("interval", glb_cfg.u.efc.interval, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("nh-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32("nexthop id", glb_cfg.u.efc.nh_id, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("chip-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32("chip id", glb_cfg.u.efc.chip_id, argv[index + 1]);
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_set_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_set_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return ret;
}

CTC_CLI(ctc_cli_qos_get_efc_cfg,
        ctc_cli_qos_get_efc_cfg_cmd,
        "show qos efc type (low|mid|high)",
        "Show",
        CTC_CLI_QOS_STR,
        "Enhance flow control",
        "Type",
        "Low congestion level type",
        "Mid congestion level type",
        "High congestion level type")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t glb_cfg;

    sal_memset(&glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    glb_cfg.cfg_type = CTC_QOS_GLB_CFG_EFC_CFG;

    if (CLI_CLI_STR_EQUAL("low", 0))
    {
        glb_cfg.u.efc.type = CTC_QOS_EFC_TYPE_LOW;
    }
    else if (CLI_CLI_STR_EQUAL("mid", 0))
    {
        glb_cfg.u.efc.type = CTC_QOS_EFC_TYPE_MID;
    }
    else if (CLI_CLI_STR_EQUAL("high", 0))
    {
        glb_cfg.u.efc.type = CTC_QOS_EFC_TYPE_HIGH;
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_qos_get_global_config(g_api_ldev, &glb_cfg);
    }
    else
    {
        ret = ctc_qos_get_global_config(&glb_cfg);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("%-12s: %u\n", "nh_id", glb_cfg.u.efc.nh_id);
    ctc_cli_out("%-12s: %u\n", "chip_id", glb_cfg.u.efc.chip_id);
    ctc_cli_out("%-12s: %u\n", "pri_mode", glb_cfg.u.efc.pri_mode);
    ctc_cli_out("%-12s: 0x%X\n", "pri_mask", glb_cfg.u.efc.pri_mask);
    ctc_cli_out("%-12s: %u us\n", "interval", glb_cfg.u.efc.interval);

    return ret;
}
#endif

int32
ctc_qos_cli_init(void)
{
    /*policer cli*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_create_policer_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_remove_policer_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_policer_first_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_policer_configure_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_policer_stats_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_clear_policer_stats_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_policer_stats_enable_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_policer_cmd);

    /*domain mapping*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_igs_domain_map_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_egs_domain_map_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_phb_configure_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_phb_configure_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_qos_domain_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_obm_domain_map_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_obm_domain_cmd);

    /* queue */
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_flush_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_pri_map_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_queue_pri_map_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_flexq_map_profile_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_flexq_map_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_flexq_map_cmd);

    /*shaping*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_port_shape_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_port_queue_shape_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_group_shape_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_shape_ipg_en_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_reason_shape_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_port_queue_stats_en_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_port_queue_stats_en_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_port_queue_stats_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_clear_port_queue_stats_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_shape_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_shape_base_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_shape_en_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_group_node_shape_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_group_node_shape_cmd);

    /*schedule*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_wdrr_weight_mtu_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_wdrr_weight_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_wdrr_cpu_reason_weight_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_port_queue_class_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_port_group_class_priority_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_group_wdrr_weight_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_schedule_wrr_en_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_port_sub_group_id_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_port_sub_group_id_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_sched_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_sch_create_sch_grp_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_sch_destory_sch_grp_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_sch_bind_sch_group_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_sch_bind_sch_group_node_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_sch_set_sch_group_weight_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_qos_sch_group_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_sch_set_sch_mode_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_qos_sch_mode_cmd);


    /*service*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_add_del_service_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_bind_service_cmd);

    /*drop*/
    ctc_cli_queue_drop_thrd_init();
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_port_queue_drop_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_port_queue_drop_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_resrc_ingress_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_resrc_egress_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_resrc_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_resrc_queue_drop_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_resrc_usage_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_resrc_mgr_enable_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_resrc_flow_ctl_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_resrc_flow_ctl_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_pkt_len_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_resrc_fcdl_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_resrc_fcdl_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_queue_min_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_queue_min_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_oobfc_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_oobfc_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_obm_pool_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_obm_pool_cmd);

    /*cpu reason*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_cpu_reason_map_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_cpu_reason_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_cpu_reason_dest_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_reason_shp_base_pkt_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_reason_truncation_len_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_cpu_reason_misc_param_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_cpu_reason_misc_param_cmd);

    /*global config*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_glb_cfg_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_glb_cfg_cmd);

    /*debug*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_debug_on_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_debug_off_cmd);

    /*queueu monitor drop*/
    install_element(CTC_SDK_MODE, &ctc_cli_qos_monitor_drop_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_show_monitor_drop_cmd);

#ifdef EFC_BK
    install_element(CTC_SDK_MODE, &ctc_cli_qos_set_efc_cfg_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_get_efc_cfg_cmd);
#endif

    install_element(CTC_SDK_MODE, &ctc_cli_qos_query_stats_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_qos_clear_stats_cmd);

    return CLI_SUCCESS;
}

